[**Documentation**](../../../README)

***

[Documentation](../../../README) / [@zerotal/core](../README) / env

# env

The `@zerotal/core/env` subpath — a strict, fully-typed environment schema.

Declare every variable your app reads with the [t](variables/t) field builder
(`t.string()`, `t.number()`, `t.enum([...])`, …) and hand the map to
[EnvSchema.define](variables/EnvSchema#define). The schema is parsed and validated once at import
time: missing required vars, bad numbers, invalid URLs, and out-of-range
ports all fail the boot with a single [EnvSchemaError](classes/EnvSchemaError) that lists every
failure at once. The returned object is frozen and precisely typed, so
`env.PORT` is `number` (never `undefined`) and enum fields narrow to their
literals.

## Example

```ts
import { EnvSchema, t } from "@zerotal/core/env";

export const env = EnvSchema.define({
  PORT:     t.number().default(3000),
  NODE_ENV: t.enum(["development", "production", "testing"]).required(),
  DB_HOST:  t.string().required(),
  DB_PASS:  t.string().when("NODE_ENV", "production", t.required()),
  BASE_URL: t.url().default("http://localhost:3000"),
});

console.log(env.PORT);    // number — never undefined
console.log(env.DB_HOST); // string — validated at boot
```

## Classes

- [EnvFieldError](classes/EnvFieldError)
- [Def](classes/Def)
- [EnvSchemaError](classes/EnvSchemaError)

## Type Aliases

- [FieldType](type-aliases/FieldType)
- [InferDef](type-aliases/InferDef)
- [EnvOutput](type-aliases/EnvOutput)

## Variables

- [EnvSchema](variables/EnvSchema)
- [t](variables/t)
