Config
Hierarchical configurations for your app:
Set with
export NODE_ENV=productionUses the default configuration values unless the production one explicitly has a value for that key
npm install config
mkdir config
emacs config/default.jsondefault.json
{
// Customer module configs
"Customer": {
"dbConfig": {
"host": "localhost",
"port": 5984,
"dbName": "customers"
},
"credit": {
"initialLimit": 100,
// Set low for development
"initialDays": 1
}
}
}Edit config overrides for production deployment:
emacs config/production.json
Use configs in your code:
config.get() will throw an exception for undefined keys to help catch typos and missing values. Use config.has() to test if a configuration value is defined.
Start your app server:
Running in this configuration, the port and dbName elements of dbConfig will come from the default.json file, and the host element will come from the production.jsonoverride file.
Last updated