Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
My usual nconf wrapper
"use strict";
/**
Save as config/index.js
Config files =
- config/config.json
- config/config.$NODE_ENV.json
- config/config.$NODE_ENV.$USER.json
**/
var path = require('path');
var fs = require('fs');
var conf = module.exports = require('nconf')
.argv()
.env()
.defaults({NODE_ENV: 'production'});
var files = [
path.join(__dirname, 'config.json'),
path.join(__dirname, 'config.' + conf.get('NODE_ENV') + '.json'),
path.join(__dirname, 'config.' + conf.get('NODE_ENV') + '.' + conf.get('USER') + '.json')
].filter(fs.existsSync);
console.log('Loading config from files', files);
conf.use('memory', {loadFrom: files});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment