singleconfig

Single unified YAML/mustache config for node that can handle environment variables.

npm install singleconfig
14 downloads in the last week
28 downloads in the last month

singleconfig Build Status

=====

singleconfig is a single unified YAML/mustache config for node that can handle environment variables.

With singleconfig you can:

  • Have multiple environments and inheritance in one file (via YAML)
  • Pull in environment variables (via Mustache)

Install

npm install singleconfig

Usage

Create a mustache template which gives a YAML file ('./config.yml')

defaults: &defaults
  port: 5000

development:
  <<: *defaults
  redis:
    url: 'redis://:@localhost:6379/'

test:
  <<: *defaults
  port: 3000
  redis:
    url: 'redis://:@localhost:9999/'

production:
  <<: *defaults
  port: {{ env.PORT }}
  redis:
    url: {{ env.REDISTOGO_URL }}

Use your config(defaults to './config.yml'):

var config = require('singleconfig')
console.log(config.port)
console.log(config.redis.url)

Output:

5000
redis://:@localhost:6379/

Change your environment using env variables(defaults to development):

export NODE_ENV='production' 
export PORT=7000
export REDISTOGO_URL=redis://wee:wee@someredistogo.com:9999/

Output (for production):

7000
redis://wee:wee@someredistogo.com:9999/

Use a different config path:

// CONFIG_PATH must be set either in the system environment or at runtime
process.env['CONFIG_PATH'] = '/my/super/custom/path/configy.file'
var config = require('singleconfig')
npm loves you