Skip to content

EnvParser

Defined in: types.ts:87

A parsed environment with typed lookups.

T extends EnvObject = EnvObject

readonly env: T

Defined in: types.ts:92

The fully parsed env object. Exposed if you need direct access, but prefer get() for individual lookups.

deprecate(oldKey, newKey): void

Defined in: types.ts:143

Log a warning locally when an old key is still present, to remind you to finish a migration. No-ops in deployed environments.

string

string

void

parser.deprecate("database_url", "db__primary__url");

get(key): Primitive | EnvObject | undefined

Defined in: types.ts:118

Retrieve a value from the parsed env using any key syntax. All four forms resolve identically for nested keys:

get(“SERVICE__DB__URL”) // uppercase + double underscore → traversal get(“service__db__url”) // lowercase + double underscore → traversal get(“service.db.url”) // dot syntax → traversal get(“service_db_url”) // single underscore → flat key lookup

Returns undefined and warns locally (via observe) if the key doesn’t exist. Returns a nested EnvObject if the path resolves to a namespace rather than a leaf. The consuming app decides what to do with undefined — get() never crashes for you.

string

Primitive | EnvObject | undefined

// required — app enforces this, not the library
const url = get("database_url");
if (!url) throw new Error("DATABASE_URL is required");
// optional with default
const port = get("port") ?? 3000;
// rename fallback
const url = get("db.primary.url") ?? get("database_url");

map<C>(fn): C

Defined in: types.ts:134

Define your app’s config shape in one place. Receives get() so every value is a resolved env lookup. Fallbacks between old and new key names are plain JS — no magic.

C

(get) => C

C

export const config = parser.map((get) => ({
port: get("port") ?? 3000,
database: {
url: get("db.primary.url") ?? get("database_url"),
},
allm: get("allm.service"), // returns the whole nested object
}));