Created
September 8, 2014 15:20
-
-
Save naholyr/2be869281b837b36055d to your computer and use it in GitHub Desktop.
My usual nconf wrapper
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
"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