@runcapsule/get-env-config
TypeScript icon, indicating that this package has built-in type declarations

8.2.1 • Public • Published

@runcapsule/get-env-config

Hierarchical Node.js configuration with files, environment variables. Configs have the following priority (from lowest to highest):

  1. Default config env.ts
  2. Local config env.local.ts
  3. Environment config env.development.ts
  4. Local Environment config env.development.local.ts
  5. All above rules for configs found in the rest of directories from configsDir.
  6. Environment variables

Installation

npm install -D @runcapsule/get-env-config@latest

or

yarn add -D @runcapsule/get-env-config@latest

Usage example

import { getConfig } from '@runcapsule/get-env-config';

const envConfig = getConfig(CONFIG_NAME, {
  configsDir: BASE_CONFIGS_DIR,
  environment: ENVIRONMENT_NAME,
});

// Now you can refer to this config from anywhere

API

getConfig(options)

Options object itself is required.

options.configsDir(String | String[])

Base configs directory or directories. Will use it to search for configs.

options.environment(String?)

Optional environment name. Will be added to base config name. For example for environment produciton will be required following configs:

CONFIGS_DIR/env.ts
CONFIGS_DIR/env.local.ts
CONFIGS_DIR/env.produciton.ts
CONFIGS_DIR/env.produciton.local.ts

loadConfigIntoProcessEnv(options)

Will follow all rules of getConfig but instead of return resulting config it will load into process.env.

getHelpers(config, properties)

getHelpers(config, [
  'SECURE',
  'PRIVATE',
  {
    dev: config.NODE_ENV === 'development',
    prod: config.NODE_ENV === 'production',
    test: config.NODE_ENV === 'test',
  },
])

Result will have:

  • properties with boolean values: ['isSecure', 'isPrivate', 'isDev', 'isProd', 'isTest']
  • functions, that can accept up to 2 arguments and return 1st arg if flag is truthy and 2nd arg if flag is falsy: ['ifSecure', 'ifPrivate', 'ifDev', 'ifProd', 'ifTest]
  • functions, that can accept up to 2 arguments and return 1st arg if flag is falsy and 2nd arg if flag is truthy: ['ifNotSecure', 'ifNotPrivate', 'ifNotDev', 'ifNotProd', 'ifNotTest]

printConfig(config)

Pretty print sorted config values into console.

Readme

Keywords

none

Package Sidebar

Install

npm i @runcapsule/get-env-config

Weekly Downloads

0

Version

8.2.1

License

ISC

Unpacked Size

20.2 kB

Total Files

32

Last publish

Collaborators

  • bauxy
  • gbiryukov
  • bauxy-dev
  • pkozlov