Easy environment variable manager.Process ENV
Easy environment variable manager.
$ npm install --save process-env
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.
By default it does not overwrite any pre-existing variables either as part of the environment being ran in, or loaded by the
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.
Then you can load it like:
Now when you do
env.get('node_app');you will see
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.
$ npm test
(The MIT License)
Copyright (c) 2015 Josh Manders <email@example.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.