Skip to content

Instantly share code, notes, and snippets.

@cpsubrian
Created November 22, 2011 23:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cpsubrian/1387428 to your computer and use it in GitHub Desktop.
Save cpsubrian/1387428 to your computer and use it in GitHub Desktop.
nconf with multiple files
$ node app.js
My specific title
green
undefined
nconf = require('nconf');
nconf.add('global', {type: 'file', file: 'global.json'})
nconf.add('user', {type: 'file', file: 'user.json'})
nconf.load();
console.log(nconf.get('title'));
console.log(nconf.get('color'));
console.log(nconf.get('movie'));
{
"title": "My generic title",
"color": "red",
"movie": "Kill Bill"
}
{
"author": "Brian Link <cpsubrian@gmail.com>",
"name": "nconf_example",
"version": "0.0.1",
"repository": {
"url": ""
},
"main": "app.js",
"engines": {
"node": "~0.6.2"
},
"dependencies": {
"nconf": "0.4.x"
},
"devDependencies": {}
}
{
"title": "My specific title",
"color": "green"
}
@ryan-williams
Copy link

I'm banging my head against what seems to be very unintuitive behavior of nconf and stumbled across this. Was this designed to show how nconf doesn't handle multiple files, i.e. the 'global' settings are clobbered by the 'user' settings?

@flanzerc
Copy link

flanzerc commented Apr 8, 2015

I believe if same key is present in multiple files then the value from the first file (in order they are defined) will be considered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment