Skip to content

@jessefulton /config.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Node.js - merge environment variables + config file + command line args
/**
* Merges environment variables + config file + command line args
*
* To use, from app.js:
* var conf = require('./config').init();
*/
var argv = require('optimist').argv;
function init() {
//1. check process.env
//2. config files override
//3. command line args final override
var vars = [
"GOOGLE_API_KEY",
"GOOGLE_CSE_ID",
"MONGODB_URI",
"LOGGLY_SUBDOMAIN",
"LOGGLY_INPUT_KEY"
];
var config = {};
var fileConfig = {};
try {
fileConfig = require('./conf/config.js');
} catch(e) {}
vars.forEach(function(el, idx, arr) {
config[el] = process.env[el];
if (fileConfig[el]) { config[el] = fileConfig[el]; }
if (argv[el]) { config[el] = argv[el]; }
});
return config;
}
exports.init = init;
//Fill in your accounts below and place in ./conf/config.js (see fileConfig var in config.js)
module.exports = {
GOOGLE_API_KEY: ""
, GOOGLE_CSE_ID: ""
, MONGODB_URI: ""
, LOGGLY_SUBDOMAIN: ""
, LOGGLY_INPUT_KEY: ""
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.