Difference between revisions of "Configuration in Node"
From Logic Wiki
(Created page with "Category:Node.js == Installation == npm i config == Usage == === index.js === <pre class="brush:js;"> const config = require('config'); //Configuration console.log("Appl...") |
(No difference)
|
Revision as of 12:06, 5 November 2018
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"
}
}