json-evn-configurator
Creates JS object with fields that are merged from environmental variables and fields from json file
Usage example
- Create config.json file with some configuration fields:
- Pass the path to the config.json file to the json-env-configurator:
const configurator = ;const config = ; console; // -> some config dataconsole; // -> another config data
-
If you specify environmental variable with the same name as in config.json file, environmental variable will has higher priority:
CONFIGURATION_FIELD_2=overridden node app.js
app.js:
const configurator = ;const config = ; console; // -> some config dataconsole; // -> overridden
- You can specify special prefix for environmental variables to separate configuration by environmental variables with namespaces
Let's create another configuration file - config2.json:
FIRST_CONFIG.CONFIGURATION_FIELD_2=overridden SECOND_CONFIG.PORT=8080 node app.js
app.js:
const configurator = ;const firstConfig = ;const secondConfig = ; console; // -> some config dataconsole; // -> overridden console; // -> localhostconsole; // -> 8080