check-env
Makes sure that all required environment variables are set.
Install
```sh $ npm install --save check-env ```Usage
```js var checkEnv = require('check-env'); checkEnv('REQUIREDVAR', 'OTHERVAR', 'ENVVAR'); // => Throws an error if one of the variables aren't set. ```CLI Usage
- Install as a project dependency as above
- Add to a lifecycle script such as
`prestart`
npm start
will bail out (exit(1)
) with a hard to miss error message if environment variables are not set
Example:
In package.json: ```json { "prestart": "check-env AWSKEY MONGOURL", "start": "node index.js" } ``` ``` $ echo $MONGOURL(nothing)
$ npm start
< Missing environment variable MONGOURL >
----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
$ echo $?
1
```