ericclemmons / ericclemmons/grunt-express-server
Allow setting of arbitrary process.env variables
- Dominant language
- JavaScript
- Stars
- 249
- Forks
- 59
- PR merge metrics
- No merged PRs in 30d
Description
Hi Eric,
Thank you for this useful grunt task. Great work!
Currently, `grunt-express-server` supports overriding two environment variables, PORT and NODE_ENV. I feel it'd be nice to extend this and allow overriding of more variables, or allow setting of arbitrary variables.
**My solution**
Such overrides can be achieved by setting an `env` option object. The `port` and `node_env` options will be retained for backwards-compatibility, but they will be overriden if a different value is specified inside the `env` option. So basically something like this:
```
express: {
options: {
port: 3000,
node_env: 'production',
env: {
DEBUG: 'server', //Sets a new variable
PORT: 3001 //Overrides the value set using the port option above
}
}
}
```
Then, inside `lib/server.js`, I plan on extending the `env` object passed in to the call to `grunt.util.spawn` with the values supplied by the user. This can be implemented [the way underscore.js implements `extend()`](http://underscorejs.org/docs/underscore.html#section-85).
If you agree, I'm willing to submit a pull request!
**My use case**
I was trying to get the `grunt-express-server` task to work with boilerplate code generated by the [official express generator](http://expressjs.com/starter/generator.html).
The boilerplate server requires an environment variable (DEBUG) to be set, for it to log anything out to the command line. You mention in the README that none of the subsequent tasks will be executed if nothing's logged out to the command line by the server.
I found no way of setting arbitrary environment variables with `grunt-express-server`'s options, so I hacked this feature into my local copy.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.