Skip to content

Instantly share code, notes, and snippets.

@sscovil
Created May 12, 2016 16:11
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 sscovil/d7f20a8aad807e334d622d86a247b4c7 to your computer and use it in GitHub Desktop.
Save sscovil/d7f20a8aad807e334d622d86a247b4c7 to your computer and use it in GitHub Desktop.
Use multiple JS files as defaults for nconf: https://github.com/indexzero/nconf/issues/96
module.exports = {
ENV: 'set by development.js',
ARG: 'set by development.js',
DEV: 'set by development.js'
};
var config = require('nconf');
var extend = require('node.extend');
var env = process.env.NODE_ENV || 'development';
config.use('memory')
.env('__')
.argv()
.defaults(extend(true, {}, require('./environments/all'), require('./environments/' + env)));
/**
* Run this on the command line:
* $ ENV='set by environment variable' node config.js --ENV 'set by command line arg' --ARG 'set by command line arg'
*
* Output:
* ENV: set by environment variable
* ARG: set by command line arg
* DEV: set by development.js
* ALL: set by all.js
*/
console.log('ENV: ' + config.get('ENV'));
console.log('ARG: ' + config.get('ARG'));
console.log('DEV: ' + config.get('DEV'));
console.log('ALL: ' + config.get('ALL'));
module.exports = {
ENV: 'set by all.js',
ARG: 'set by all.js',
DEV: 'set by all.js',
ALL: 'set by all.js'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment