process-env

Easy environment variable manager.

Process ENV

Easy environment variable manager.

Install

$ npm install --save process-env

Usage

Process ENV allows you to not only get your environment variables, but also set them in your scripts, or even load a .envfile which will set variables for you.

import env from 'process-env'

env.get('path'); // returns: /usr/local/bin:/usr/bin

You can set a variable by passing the value you want as a second parameter.

env.set('path', '/usr/bin');

By default it does not overwrite any pre-existing variables either as part of the environment being ran in, or loaded by the .envfile.

To overwrite any pre-existing variable, pass trueas the 3rd argument.

env.set('path', '/usr/bin', true);

By default we check for a .envfile and load that if it exists, but you can load your own file if you'd like. For example, create a file called my.envand put the contents below inside.

NODE_APP=My-App
APP_VERSION=1.0.0

Then you can load it like:

env.load('./my.env');

Now when you do env.get('node_app');you will see My-App.

As you can see, all examples reference variables in lowercase. That doesn't matter, as internally we .toUpperCase()on the key to make sure all variables are uppercased as they should be.

Testing

$ npm test

Credits

License

(The MIT License)

Copyright (c) 2015 Josh Manders <josh@joshmanders.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Repository

https://github.com/joshmanders/process-env.git


上一篇:@types/gulp-nodemon
下一篇:ipware

相关推荐

官方社区

扫码加入 JavaScript 社区