Envigorate is a simple module for populating configuration objects with environment variables.
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 intoconfig
. Defaults toprocess.env
.strict
:boolean
- An optional argument denoting whether or not an error should be raised when a variable is referenced inconfig
that is not present inenv
.
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.
Error thrown by envigorate()
when undefined variables are referenced in config
. Has a variables
property containing the names of the undefined variables.
.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