Created
November 22, 2011 23:38
-
-
Save cpsubrian/1387428 to your computer and use it in GitHub Desktop.
nconf with multiple files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node app.js | |
My specific title | |
green | |
undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"title": "My generic title", | |
"color": "red", | |
"movie": "Kill Bill" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"author": "Brian Link <[email protected]>", | |
"name": "nconf_example", | |
"version": "0.0.1", | |
"repository": { | |
"url": "" | |
}, | |
"main": "app.js", | |
"engines": { | |
"node": "~0.6.2" | |
}, | |
"dependencies": { | |
"nconf": "0.4.x" | |
}, | |
"devDependencies": {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"title": "My specific title", | |
"color": "green" | |
} |
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
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?