singleconfig

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

singleconfig

=====

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)
npm install singleconfig

Let's use this mustache template for a YAML config file (config.yml.mustache)

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:

var config = require('singleconfig')('/path/to/my/config.yml.mustache')
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/