1.0.2 • Published 6 years ago

@ecocea/config-loader v1.0.2

Weekly downloads
18
License
MIT
Repository
github
Last release
6 years ago

@ecocea/config-loader

NPM Module for Environment Config Load

Use a default configuration file, and overwrite it with an environment specific configuration file.
This use Lodash _.mergeWith() function, however arrays are not merged but replaced.

Prerequisites

Tested on Node.js 8+
Requires ES6 compatibility

Installation

npm install @ecocea/config-loader --save

Initialisation

//Path of the directory containing global and environments configurations
const configPath = path.join(__dirname, './config');
  
//Environment config that should be loaded
const env = process.env.environment;
  
//Retrieve the merge configuration of global and specified environment
const config = require('@ecocea/config-loader')(configPath, env);

Other calls

const config = require('@ecocea/config-loader');

Config load and Customization

The script expect a file named config.js in the configPath, and every environment config file should be named config_{env}.js You can customize the configuration file name, and the separator between filename and environment:

//Mandatory
const configPath = path.join(__dirname, './config');
const env = process.env.environment;
  
//Optionnal
const configName = "properties";
const configSeparator = "-";
  
//First call
const config = require('@ecocea/config-loader')(configPath, env, configName, configSeparator);

Tips for Heroku

Avoid using too much Heroku Config Vars. If you want the ability to quickly override a config var without deploying, you can do:

const myConfigVar = process.env.MY_CONFIG_VAR || 'ThisIsMyConfigVar';

Migrating from 0.x.x to 1.x.x

At first call, remove the init method
For other calls, remove all .getConfig()

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.1

6 years ago