1.4.0 • Published 4 years ago

@dicehub/config-env-loader v1.4.0

Weekly downloads
126
License
MIT
Repository
github
Last release
4 years ago

@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

1.4.0

4 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.0

6 years ago