@dicehub/config-env-loader

Loads global configurations for client and server from root directory

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
15May 29, 2021Aug 9, 2018Minified + gzip package size for @dicehub/config-env-loader in KB

Readme

@dicehub/config-env-loader

npm version

Load configuration files based on NODE_ENV variable

Install

npm install @dicehub/config-env-loader -S

# via yarn
yarn add @dicehub/config-env-loader

Usage

Set NODE_ENV

Only the file that corresponds to the NODE_ENV variable will be included

$ export NODE_ENV=development

Create configuration file config/development.yaml:

# <root>/config/development.yaml

TEST_VAR: 20

Include the plugin in your entry file

// <root>/index.js

require('@dicehub/config-env-loader')({
  // Config directory
  configPath: './config/',
});

And now, every variable that is in the file config/development.yaml is available through the process.env

console.log(process.env.DEVELOPMENT_ENV_VAR) // '42';

The value is string because https://nodejs.org/dist/latest-v10.x/docs/api/process.html#process_process_env

Options:

var conf = require('@dicehub/config-env-loader')({
  // The directory where the configuration files for the NODE_ENV are located
  configPath: './config/',

  // The array of files to be included, not depending on the NODE_ENV
  include: ['./common-config.yaml']
});

// The variable conf contains all that is included
// Except that the types are not converted
process.env.TEST_VAR // '42'
conf.TEST_VAR // 42

Default config file

  1. By default, if NODE_ENV is not provided, the configuration development.yaml is loaded
  2. if in config folder there is a file general.yaml then it will be loaded before the {NODE_ENV}.yaml

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.