node-env-loader
v1.0.6
Published
load env config
Downloads
8
Maintainers
Readme
node-env-loader
Install
yarn add node-env-loader
# or
npm install --save node-env-loader
Usage
Create env.json
in the root directory
{
"NODE_ENV": "development",
"LOCAL": true
}
Load the config
// app.js
import envLoader from 'node-env-loader'
envLoader({
path: './env.json', // default to be './env.json'
encoding: 'utf8', // default to be 'utf8'
})
/**
* shorthand
* envLoader('./env.json')
*/
console.log(process.env.NODE_ENV) // 'development'
console.log(process.env.LOCAL) // 'true'
It won't cover which existed
// app.js
import envLoader from 'node-env-loader'
process.env.NODE_ENV = 'production'
envLoader()
console.log(process.env.NODE_ENV) // 'production'