A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/whynotsoluciones/node-env-configuration below:

whynotsoluciones/node-env-configuration: A node.js module that helps with loading of hierarchical configuration from environment variables as suggested by twelve factor methodology www.12factor.net/config

node-env-configuration is a node.js module that helps with loading configuration as suggested by twelve factor methodology www.12factor.net:

The twelve-factor app stores config in environment variables (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code; unlike config files, there is little chance of them being checked into the code repo accidentally; and unlike custom config files, or other config mechanisms such as Java System Properties, they are a language- and OS-agnostic standard. … In a twelve-factor app, env vars are granular controls, each fully orthogonal to other env vars. They are never grouped together as “environments,” but instead are independently managed for each deploy. This is a model that scales up smoothly as the app naturally expands into more deploys over its lifetime.

Suppose you have this json default configuration for your node application:

var defaultConfiguration = {
  http_port: 8000,
  https_port: 8001,
  mongodb: {
    name: 'api', // Database name
    host: '127.0.0.1', // Database host
    user: '', // Database user
    password: '', // Database password
    port: 27017,
    options: {} // MongoDB options
  }
}

Then you want to override this configuration (or subset of it) for your production environment. You define the next environment variables :

API_APP_HTTP_PORT='80';
API_APP_HTTPS_PORT='443';
API_APP_MONGODB_NAME='api_db';
API_APP_MONGODB_HOST='api.example.com';
API_APP_MONGODB_USER='username';
API_APP_MONGODB_PASSWORD='secret password';

In your code your can override defaultConfiguration object with these environment variables:

var nodeenvconfiguration = require('node-env-configuration');
var config = nodeenvconfiguration({
  defaults: defaultConfiguration,
  prefix: 'apiApp' // Read only env vars starting with API_APP prefix
});
API_APP_MONGODB_NAME = 'api_db'  # Matches obj.mongodb.name property
API_APP_MONGODB_URL_HOST = 'api.example.com'  # Matches obj.mongodb.url.host propery
Name Default Value Description prefix '' Pascal case prefix. Restrict variables to read from environment to those starting with this prefix in snake case arraySeparator null This character, if specified, is used as an array separator. So if a variable contains this character, the variable is parsed as an array of values defaults {} Default object values

MIT


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4