Created
May 12, 2016 16:11
-
-
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
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
module.exports = { | |
ENV: 'set by development.js', | |
ARG: 'set by development.js', | |
DEV: 'set by development.js' | |
}; |
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
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')); |
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
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