npm.io
0.1.0 • Published 6 years ago

simple-envvar-override-config

Licence
ISC
Version
0.1.0
Deps
0
Size
7 kB
Vulns
0
Weekly
0

simple-envvar-override-config

Allows you to read in a config file and selectively overwrite values based off of environment variables.

Config can be a file or just a dictionary

Example

Given the following config file:

{
    "name" : "nameval",
    "complex" : {
        "name" : "complexnameval",
        "num" : 100
    }
}

And the following environment variables:

ENVCONFIG_name = "newnameval"
ENVCONFIG_complex.num = "500"
ENVCONFIG_newvariable = "new variable value"
ENVCONFIG_newcomplex.newnum = "1000.5"

Then running the following code:

const override_config = require('simple-envvar-override-config');
const new_config = override_config('/path/to/config.json');
console.log(new_config);

Will print the following:

{
  "name": "newnameval",
  "complex": { 
      "name": "complexnameval", 
      "num": "500" 
  },
  "newvariable": "new variable value",
  "newcomplex": { 
      "newnum": "1000.5" 
  }
}

TODOS

  1. Handle arrays
  2. Handle defining "type" of value in env var. Right now everything is a string

Keywords