1

I am using a template object map that contains key/value pairs representing object properties, and environmental variable names.

As an example... I want to to have the following object

   var template = {
        propA: 'ENV_VAR_PROP_A',
        propB: 'ENV_VAR_PROP_B',
        propC: {
            propD: 'ENV_VAR_PROP_D'
        }
    }

and I want to use the following function

var parseConfig = function (template) {
    var config = {};
    for(var prop in template){
        var key = template[prop];
        var val = process.env[key];
        if(val) {
            config[prop] = val;
        }
    }
    return config;
};

NOTE The function above does not work for me since it is not going more than one layer deep on the properties.

The result of parsing the template should be an object such as the following

var template = {
    propA: '{result of process.env.ENV_VAR_PROP_A}',
    propB: '{result of process.env.ENV_VAR_PROP_B',
    propC: {
        propD: '{result of process.env.ENV_VAR_PROP_D}'
    }
}
TheJediCowboy
  • 8,924
  • 28
  • 136
  • 208

0 Answers0