Zero-dependency lib that loads environment variables from .env.${ENV_NAME}
files
npm install dotenvdotenv --save
Require the lib as early as possible in your app
require('dotenvdotenv');
Create the .env.dev
and .env.test
files in the root directory and add environment variables on new lines as KEY=VALUE
For example:
REDIS_HOST=localhost
REDIS_PORT=32776
The vars are now available on process.env
redis: {
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT
}
If the .env.${ENV_NAME}
files do no exist, an error will be raised
Node:
- v0.10
- v0.12
- v4
- v5
- v6
No. .env.${ENV_NAME}
files should not be committed to version control. Your production environment should use the environment variables
Existing environment variables will not be overwritten