@dicehub/config-env-loader

1.4.0 • Public • Published

@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

Package Sidebar

Install

npm i @dicehub/config-env-loader

Weekly Downloads

2

Version

1.4.0

License

MIT

Unpacked Size

6.48 kB

Total Files

7

Last publish

Collaborators

  • rostikl