env-dyn-config
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

env-dyn-config

env-dyn-config is simple approach for dynamic configuration files. It breaks down the configuration depending on the environment distinguiting the base from the env's specifics.

Install

Recommended to install locally

npm install env-dyn-config --save

Or installing with yarn? yarn add env-dyn-config

Usage

1. Environment

Since this uses the dotenv package, create a .env file in the root of your project:

NODE_ENV="development"

2. env-dyn-config intialization

Add the following file to initialize the module.

/// env-dyn-config.config.ts
import init from "env-dyn-config";

export default init();

3. Your first config

Add your config file.

/// config.ts
import edc from "./env-dyn-config.config";
const { combine, environments } = edc;

const specific = {
    [environments.production]: {
        property: "for your dear clients"
    }
}

export default combine({
    property: "for devs only"
}, specific);

NB: as early as possible in your application, import / configure env-dyn-config. Once imported, the returned value of each exported combine remains the same (since its cached).

For more examples see repo env-dyn-config-examples

Documentation

This package exposes a function, once runned, returning:

  • environments the list of environment names
  • ENV the current environment recognized by dotenv
  • fusion a method to merge configurations

Package Sidebar

Install

npm i env-dyn-config

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

12.1 kB

Total Files

17

Last publish

Collaborators

  • nickfielton