Skip to content

Instantly share code, notes, and snippets.

@naholyr
Created September 8, 2014 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naholyr/2be869281b837b36055d to your computer and use it in GitHub Desktop.
Save naholyr/2be869281b837b36055d to your computer and use it in GitHub Desktop.
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