Last active
December 22, 2015 22:59
-
-
Save jrf0110/6543848 to your computer and use it in GitHub Desktop.
Boilerplate node.js app configuration
This file contains hidden or 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 utils = require('./lib/utils'); | |
var config = {}; | |
/** | |
* Change configuration environment | |
* @param {String} env The environment to change to | |
*/ | |
var changeEnvironment = function(env){ | |
if (env == null || !config.hasOwnProperty(env)) env = 'dev'; | |
for (var key in module.exports) delete module.exports[key]; | |
var _config = {}; | |
_config = utils.merge( utils.clone(config.default), config[env] ); | |
for (var key in _config) module.exports[key] = _config[key]; | |
module.exports.env = env; | |
// Re-export this function since it was overwritten in the environment switch | |
module.exports.changeEnvironment = changeEnvironment; | |
}; | |
/** | |
* Default Configuration | |
* Specific environments will override defaults | |
*/ | |
config.default = { | |
// HTTP Port for app | |
httpPort: process.env.NEW_APP_PORT || 3013 | |
// Cookie secret | |
, cookieSecret: process.env.NEW_APP_COOKIE_SECRET || 'default cookie secret OMNOM' | |
}; | |
/** | |
* Test Configuration | |
*/ | |
config.test = { | |
}; | |
/** | |
* Dev Configuration | |
*/ | |
config.dev = { | |
}; | |
/** | |
* Production Configuration | |
*/ | |
config.prod = { | |
}; | |
module.exports = {}; | |
// Set the initial environment | |
changeEnvironment( process.env.NEW_APP_ENV || 'dev' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment