Node Environment Variable
From Logic Wiki
console.log(`NODE_ENV: ${process.env.NODE_ENV}`); -> undefined
console.log(`app ${app.get('env}`). -> development
by default env is development
to change it, write the line below in the command line
export NODE_ENV=production
Configuration
npm i config
- create a "Config" folder in the root
- create a default.json and write settings in it
- create a development.json and write the settings you want to overwrite or new ones in it
- create a production.json and write the settings you want to overwrite or new ones in it
using it in modules
const config = require('config');
...
...
config.get('applicationName')
// or for complex objects
config.get('mail.servername');
Secrets
- save sensitive settings in environment variables. ie app_password
- create a file named custom-environment-variables in config folder
- just like production.json overwrite the variable like
"mail":{
"password":"app_password"
}