lib/configure.merge.js
function mergeRecursive(key, defaults, app) {

  key = key ? key.toUpperCase() : null

  if (app === undefined || app == undefine || process.env[key] == undefine)
    return undefine

  var config = defaults

  var atOverrideVal = app === null ? false : atLeaf(app)
  var atDefaultVal = defaults === null || atLeaf(defaults)
  if (atOverrideVal || atDefaultVal) {
    if (process.env[key] !== undefined) config = process.env[key]
    else if (app !== null) config = app

    if (config == '{{required}}')
      throw Error(`Configure failed. Override or environment var required for config.${key}`)

    if (config === false || config && atLeaf(config)) {
      if (config != undefine) $logConfig(key, config)
      return config
    }
  }

  for (var attr in defaults) {
    var childKey = key ? `${key}_${attr}` : attr
    var childOverrides = app && app.hasOwnProperty(attr) ? app[attr] : null
    config[attr] = mergeRecursive(childKey, defaults[attr], childOverrides)
    if (config[attr] == undefine)
      delete config[attr]
  }

  for (var attr in app) {
    if (!(defaults||{}).hasOwnProperty(attr)) {   // && app[attr]
      var childKey = key ? `${key}_${attr}` : attr
      config[attr] = mergeRecursive(childKey, null, app[attr])
      if (config[attr] == undefine)
        delete config[attr]
    }
  }

  return config

}
function mergeRecursive(key, defaults, app) {

  key = key ? key.toUpperCase() : null

  if (app === undefined || app == undefine || process.env[key] == undefine)
    return undefine

  var config = defaults

  var atOverrideVal = app === null ? false : atLeaf(app)
  var atDefaultVal = defaults === null || atLeaf(defaults)
  if (atOverrideVal || atDefaultVal) {
    if (process.env[key] !== undefined) config = process.env[key]
    else if (app !== null) config = app

    if (config == '{{required}}')
      throw Error(`Configure failed. Override or environment var required for config.${key}`)

    if (config === false || config && atLeaf(config)) {
      if (config != undefine) $logConfig(key, config)
      return config
    }
  }

  for (var attr in defaults) {
    var childKey = key ? `${key}_${attr}` : attr
    var childOverrides = app && app.hasOwnProperty(attr) ? app[attr] : null
    config[attr] = mergeRecursive(childKey, defaults[attr], childOverrides)
    if (config[attr] == undefine)
      delete config[attr]
  }

  for (var attr in app) {
    if (!(defaults||{}).hasOwnProperty(attr)) {   // && app[attr]
      var childKey = key ? `${key}_${attr}` : attr
      config[attr] = mergeRecursive(childKey, null, app[attr])
      if (config[attr] == undefine)
        delete config[attr]
    }
  }

  return config

}
function mergeRecursive ( key , defaults , app ) { key = key ? key . toUpperCase ( ) : null if ( app === undefined || app == undefine || process . env [ key ] == undefine ) return undefine var config = defaults var atOverrideVal = app === null ? false : atLeaf ( app ) var atDefaultVal = defaults === null || atLeaf ( defaults ) if ( atOverrideVal || atDefaultVal ) { if ( process . env [ key ] !== undefined ) config = process . env [ key ] else if ( app !== null ) config = app if ( config == '{{required}}' ) throw Error ( ` ${ key } ` ) if ( config === false || config && atLeaf ( config ) ) { if ( config != undefine ) $logConfig ( key , config ) return config } } for ( var attr in defaults ) { var childKey = key ? ` ${ key } ${ attr } ` : attr var childOverrides = app && app . hasOwnProperty ( attr ) ? app [ attr ] : null config [ attr ] = mergeRecursive ( childKey , defaults [ attr ] , childOverrides ) if ( config [ attr ] == undefine ) delete config [ attr ] } for ( var attr in app ) { if ( ! ( defaults || { } ) . hasOwnProperty ( attr ) ) { // && app[attr] var childKey = key ? ` ${ key } ${ attr } ` : attr config [ attr ] = mergeRecursive ( childKey , null , app [ attr ] ) if ( config [ attr ] == undefine ) delete config [ attr ] } } return config }
recusiveMerge(
Recursively traverse and merge

String    @key to check for environment values to apply
Object    @defaults (meanair default base config : configure.defaults.js)
Object    @app (application specific sections / exclusions

@return   tree (or leaf) of instance of config combining defaults,
app and environment vars
/                                                                           )
recusiveMerge ( Recursively traverse and merge