ncon
v0.1.1
Published
Configuration by environment for nodejs
Downloads
6
Readme
ncon
Configuration by environment for nodejs
Install
$ npm install ncon
Usage
Create a single directory for all configuration files (.json).
In this case I have 'config/mongo.json'
.
ncon needs to be boostrapped with location of config files Example bootstrap (app.js or similar file):
app.js
// Bootstraps ncon with config files dir
var config = require('ncon');
config.init(__dirname + '../config');
Once ncon has been initialized, there is not need to initialize it later:
mongo.js
// Get mongo configuration
var config = require('ncon');
var mongoConfig = config.get('mongo');
Config Files And Environments
ncon can merge config based on the NODE_ENV, or can be overriden in the init
function
Lets say my config directory looks like this:
config/
mongo.json
mongo.development.json
mongo.production.json
mongo.test.json
mongo.json
acts as the default configuration file
mongo.*.json
will extend and overwrite any properties (and nested properties) in mongo.json
*
is desired environment
The default environment is development
. This can be overriden in two ways
Example 1: Hard code the desired environment
var config = require('ncon');
// Load and merge 'test' environment files
config.init(__dirname + '../config', 'test');
Example 1: Use environment variables
$ NODE_ENV=development node app.js
// Load 'test' environment files
var config = require('ncon');
// Load and merge 'test' environment files
config.init(__dirname + '../config');