Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 1.04 KB

File metadata and controls

41 lines (29 loc) · 1.04 KB

ProcessEnv

Node.js implementation of the Env abstraction, backed by process.env by default. Accepts an optional variables record to override the source. Provides typed access to environment variables with getString, getNumber, and getBoolean families.

See Env README for the full interface and usage.

Usage

import { Container } from "@webiny/di";
import { Env } from "@webiny/stdlib";
import { ProcessEnvFeature } from "@webiny/stdlib/node";

const container = new Container();
ProcessEnvFeature.register(container);
const env = container.resolve(Env);

const port = env.getNumber("PORT", 3000);

With custom variables (DI)

ProcessEnvFeature.register(container, {
  variables: { ...process.env, MY_VAR: "overridden" }
});

Without DI

import { createProcessEnv } from "@webiny/stdlib/node";

// Defaults to process.env
const env = createProcessEnv();

// With custom variables
const env = createProcessEnv({
  variables: { ...process.env, MY_VAR: "overridden" }
});