Skip to content

Instantly share code, notes, and snippets.

@pstaender
Last active December 17, 2015 16:59
Show Gist options
  • Save pstaender/5642971 to your computer and use it in GitHub Desktop.
Save pstaender/5642971 to your computer and use it in GitHub Desktop.
Merging of environments in config.yml including a getter to access config values by string
require('js-yaml')
data = require('./config.yml')
_ = require('underscore')
defaultEnv = 'development'
env = process.env.NODE_ENV or
config = _.extend(data[defaultEnv], data[env] or {})
config.byString = (o, s) ->
a = s.split('.')
while a.length
n = a.shift()
if n of o
o = o[n]
else
return
o
config.get = (key, value) ->
if key?.split('.')?.length > 1 then config.byString(config,key) else config[key] or null
module.exports = exports = config
# Example:
# config.get('db.mongodb.url')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment