Difference between revisions of "Configuration in Node"
From Logic Wiki
(→default.json) |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 26: | Line 26: | ||
} | } | ||
</pre> | </pre> | ||
| + | |||
=== development.json === | === development.json === | ||
<pre class="brush:js;"> | <pre class="brush:js;"> | ||
Latest revision as of 12:08, 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"
}
}