Skip to content

Instantly share code, notes, and snippets.

@admataz
Last active August 29, 2015 14:21
Show Gist options
  • Save admataz/42c676fe8069182c35e2 to your computer and use it in GitHub Desktop.
Save admataz/42c676fe8069182c35e2 to your computer and use it in GitHub Desktop.
Using nconf to manage hierarchical configuration
/**
* Using nconf to manage hierarchical configuration
* https://www.npmjs.com/package/nconf
*/
'use strict';
var nconf = require('nconf');
var config = {
mongodb: {
db_name: 'example-api',
db_host: 'localhost',
db_user: '',
db_pw: '',
db_port: 27017
},
http: {
server_name: 'Example',
host: 'localhost',
http_port: 3000,
cookie_secret: 'longandhardtoguess'
},
google: {
browser_key: 'key_from_google',
server_key: 'key_from_google'
}
};
// step down the hierarchy - use a local settings file but don't included it in the git repos
nconf
.argv()
.env()
.file({ file: process.env.NODE_ENV + '.json' })
.file({ file: './local.json' });
nconf.defaults(config);
module.exports = nconf.get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment