Browse API packages

API · v0.23.0

env

Standard library environment variables

Member signatures use schematic object.member(...) API notation. Exported type declarations are valid TypeScript.

Read-only access to the merged runtime environment.

Node and Bun use process.env; Deno uses Deno.env. The first matching dotenv file is layered over that native environment. Browser imports use an empty environment and never include server variables in client code.

ts
import env from "@rcompat/env";

env.get#

Returns a required environment variable.

Parameters

  • key — Environment variable name.

Throws: Error when the variable is not defined.

ts
env.get(key: string): string;

env.try#

Returns an optional environment variable.

Parameters

  • key — Environment variable name.

Returns: The value, or undefined when it is not defined.

ts
env.try(key: string): string | undefined;

env.toJSON#

Returns a detached, mutable snapshot with a null prototype.

Returns: All loaded environment variables as a new dictionary.

ts
env.toJSON(): Dict<string>;