Read application settings using advanced strategies like environment variables instead:
- .env
- hardcoded values in nodejs modules/classes
- nodejs >= 10
- Create a file called: application.json at the root of workspace
{
"foo": "${FOO_VALUE}",
"bar": "baz"
}
- expose required environment variables
export FOO_VALUE=imthefoovalue
- add this snippet at the beginning of your application
const EnvSettings = require("advanced-settings").EnvSettings;
var envSettings = new EnvSettings();
var settings = envSettings.loadJsonFileSync("application.json", "utf8");
console.log(settings.foo);
-
expose the settings variable to your application using your own approach.
-
You can also use it as a promise
await envSettings.loadJsonFile("application.json", "utf8");
- how spring boot framework allow us to centralize the configuration of the app with a lot of features, one of them called Placeholders in properties
- environment variables usage is the best approach to handle the variables who change from environments: dev > testing > prod.
- see how heroku does: https://devcenter.heroku.com/articles/config-vars
JRichardsz |