config.json
nconf wrapper that simplifies work with environment specific configuration files.
config.json is easy to use; it:
- loads the default configuration file;
- loads environment specific configuration file and overrides defaults;
and then:
- uses environment variables;
- and command-line arguments to override data from configuration files.
Installation
npm install config.json
Usage
The top-level of config.json
is a function that loads configuration file with the given filepath
.
Create default configuration file
vi sample.json
Create environment specific configuration file
vi sample.development.json
Note: Environment specific configuration files should be in the same directory as the default one.
Test config.json in action
vi sample.js
var config = './sample.json'; console;console;
Run the above script:
NODE_ENV=development node ./sample.js --mongodb:host "dharma.mongohq.com" --mongodb:port 10065
The output will be:
domain: dev.example.com
mongodb:
host: dharma.mongohq.com
port: 10065
Load configuration for the specific environment
Environment can be set by passing env
argument:
var developmentConfig = './sample.json' 'development';var productionConfig = './sample.json' 'production';
One more thing...
filepath
can be empty if your configuration file is in the current working directory of the process and is called config.json.
License
Released under the MIT license.