Package to provide application config with local config and environment support. This package allows you to simply override config variables by defining local config files or environment variables.
Also isDebug
and isStage
are set based on NODE_ENV
, which can be used in your code later on.
var appConfig = require('node-application-config'),
config = appConfig(options);
options
is a hash with the following config variables:
Base path for the application and for the config package to search for configurations
default: process.cwd()
Name of the base configuration
default: config.json
Name of the local configuration (which overwrites the base config, but is not necessarily in the version control)
default: config.local.json
Prefix for environment variables that overwrite the configurations
default: app_config_
When merging config variables, the following priorities are taken into account:
- Environment variable
- Local config variable
- Config variable
config.json
{
"db": {
"user": "test",
"pass": "testPass"
"port": "10000"
}
}
config.local.json
{
"db": {
"pass": "securePass"
"host": "localhost"
}
}
environment variable
app_config_db_port=1337
... results in:
var appConfig = require('node-application-config'),
config = appConfig();
config.db.user == "test";
config.db.pass == "securePass";
config.db.host == "localhost";
config.db.port == 1337;