Configuration in Node
From Logic Wiki
Contents
Installation
npm i config
Usage
index.js
const config = require('config');
//Configuration
console.log("Application Name : " + config.get('appName'));
console.log("Mail Server Name : " + config.get('mailServer.serverAddress'));
//export contentiric_mail_password=Password123 // this env variable is mapped to mailServer.serverPassword in /config/custom-environment-variables file
console.log("Mail Server Password : " + config.get('mailServer.serverPassword'));
Setting Environment Variables in Mac
export NODE_ENV=development
export contentiric_mail_password=Password123 // this env variable is mapped to mailServer.serverPassword in /config/custom-environment-variables file
Config Transformations
in the config folder
default.json
{
"appName" : "Contentiric CMS"
}
development.json
{
"appName" : "Contentiric CMS - Development",
"mailServer" : {
"serverAddress":"mail.google.com"
}
}
custom-environment-variables.json
This file is for environment variables to config mappings and name must be exactly like this
{
"mailServer" : {
"serverPassword":"contentiric_mail_password"
}
}