nconf-loader-ex
v1.1.1
Published
Loads nconf configuration files from disk.
Downloads
5
Readme
nconf configuration file loader
Loads nconf configuration files from disk.
It looks for config.json in the specified directory. Should config.x.json exist, the configuration will be overloaded with the environment config. Should config.x.local.json exist, the configuration will be overloaded with the local config.
x is defined by NODE_ENV
environment variable (development if not set).
See NCONF for additional info.
Usage
There are two requirements to run the script:
- A wellformed json file named config.x.json where x is
NODE_ENV
or development. - Point to the directory location of the config file(s).
Load the configuration
require('nconf-loader').load(__dirname);
Example
config.json:
{
"fruit": "pear",
"drink": "beer",
"food": "spaghetti"
}
config.development.json:
{
"fruit": "apple",
"drink": "milk"
}
config.development.local.json:
{
"fruit": "ananas"
}
config.production.json:
{
"fruit": "pineapple",
"drink": "pina colada"
}
app.js:
var nconf = require('nconf');
require('nconf-loader').load(__dirname);
console.log('fruit of choice:', nconf.get('fruit'));
console.log('favourite drink:', nconf.get('drink'));
console.log('food of choice:', nconf.get('food'));
The result when running node app.js
:
fruit of choice: ananas
favourite drink: milk
food of choice: spaghetti
The result when running NODE_ENV=production node app.js
:
fruit of choice: pineapple
favourite drink: pina colada
food of choice: spaghetti