Last active
August 29, 2015 14:08
-
-
Save vvo/c97a975b403dc3bbdf8d to your computer and use it in GitHub Desktop.
The simplest configuration module you will ever need
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
// 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