envigorate
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

envigorate

Envigorate is a simple module for populating configuration objects with environment variables.

Codacy grade Codacy coverage npm GitHub

API

envigorate(config, env, strict): Record<string, unknown>

  • config: Record<string, unknown> - An object containing configuration information and possibly variable references.
  • env: Record<string, unknown> - An optional object argument conntaining the variables to be inserted into config. Defaults to process.env.
  • strict: boolean - An optional argument denoting whether or not an error should be raised when a variable is referenced in config that is not present in env.

Returns a copy of config where values matching the format "${{ FOO }}" are replaced with values from env. Optionally throws a EnvigorateMissingVariableError if references are made to unknown variables.

EnvigorateMissingVariableError

Error thrown by envigorate() when undefined variables are referenced in config. Has a variables property containing the names of the undefined variables.

Example

.env

FOOBAR=123

config.yml

test: ${{ FOOBAR }}

example.ts

import 'dotenv/config';
import { cleanEnv, num } from 'envalid';
import { envigorate } from 'envigorate';
import { readFileSync } from 'fs';
import { load } from 'js-yaml';

const config = envigorate(
  load(readFileSync('config.yml').toString()) as Record<string, unknown>,
  cleanEnv(process.env, {
    FOOBAR: num()
  })
);

console.log(config.test); // --> 123

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i envigorate

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

6.14 kB

Total Files

5

Last publish

Collaborators

  • cadpnq