Skip to content

Instantly share code, notes, and snippets.

@vvo
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vvo/c97a975b403dc3bbdf8d to your computer and use it in GitHub Desktop.
Save vvo/c97a975b403dc3bbdf8d to your computer and use it in GitHub Desktop.
The simplest configuration module you will ever need
// This module will load ./process.env.APP_ENV.json and exports it
// And will also read args from command line and merge them, i.e.:
// node index.js --server.hostname=192.168.56.1
// will work.
// Usually this module should be in ./config/index.js
// And then you use var config = require('./config');
// You must set an APP_ENV
if (!process.env.APP_ENV) {
throw new Error('You must specify an APP_ENV=environment variable');
}
var defaults = require('lodash').defaults;
var minimist = require('minimist');
var path = require('path');
var args = minimist(process.argv.slice(2));
var envConfig = require(path.join(__dirname, process.env.APP_ENV + '.json'));
module.exports = defaults(args, envConfig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment