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...") |
|||
| Line 14: | Line 14: | ||
</pre> | </pre> | ||
=== Setting Environment Variables in Mac === | === Setting Environment Variables in Mac === | ||
| + | <pre class="brush:js;"> | ||
export NODE_ENV=development | export NODE_ENV=development | ||
| − | + | </pre> | |
export contentiric_mail_password=Password123 // this env variable is mapped to mailServer.serverPassword in /config/custom-environment-variables file | export contentiric_mail_password=Password123 // this env variable is mapped to mailServer.serverPassword in /config/custom-environment-variables file | ||
== Config Transformations == | == Config Transformations == | ||
in the config folder | in the config folder | ||
=== default.json === | === default.json === | ||
| + | <pre class="brush:js;"> | ||
{ | { | ||
"appName" : "Contentiric CMS" | "appName" : "Contentiric CMS" | ||
} | } | ||
| + | </pre> | ||
=== development.json === | === development.json === | ||
| + | <pre class="brush:js;"> | ||
{ | { | ||
"appName" : "Contentiric CMS - Development", | "appName" : "Contentiric CMS - Development", | ||
| Line 30: | Line 34: | ||
} | } | ||
} | } | ||
| + | </pre> | ||
=== custom-environment-variables.json === | === custom-environment-variables.json === | ||
This file is for environment variables to config mappings and name must be exactly like this | This file is for environment variables to config mappings and name must be exactly like this | ||
| + | <pre class="brush:js;"> | ||
{ | { | ||
"mailServer" : { | "mailServer" : { | ||
| Line 37: | Line 43: | ||
} | } | ||
} | } | ||
| + | </pre> | ||
Revision as of 12:07, 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"
}
}