env12
env12 is a simple library for making it easier to handle configuration for 12 factor applications in NodeJS.
License
MIT
Reference
There is a single exported function named merge
. This function will look at process.env
and add settings into the passed in environment object.
merge
- @env: The config environment object to merge the environment variables into.
- @prefix: A prefix that the environment variables must have to be added, which will be stripped from the key in @env.
Runs through the environment variables for the process and adds them to @env if the prefix matches. All values will be coerced via JSON.parse, so they should be the correct type.
For the following examples, assume the environment has the following variables set:
foo=bar
app_foo=baz
app_baz_bar=1
Note that the value returned is from APP_FOO and not FOO as FOO was ignored because it is not prefixed.
let settings = {};
env12.merge(settings, prefix="app");
console.log(JSON.stringify(settings));
> {"app": "baz", "baz": {"bar": 1}}