@variablelab/env
v0.5.6
Published
Only declared variables, checked at boot.
Downloads
1,041
Maintainers
Readme
Contract-first environment configuration. You define the env once with a Standard Schema validator, such as Zod, Valibot or ArkType, and get a typed env object that merges per-environment config with your environment variables.
The core runs on Node, Bun, Deno, the browser, Workers and Edge. Every other entry point is opt-in.
Install
pnpm add @variablelab/envNo validator is bundled. To use Zod, the default in the docs and the validator behind @variablelab/env/zod, install it beside env:
pnpm add zodUsage
// env.ts
import { defineEnv, schema } from "@variablelab/env";
import * as e from "@variablelab/env/zod";
const Env = schema({
server: { PORT: e.port, HOST: e.host },
});
export const env = defineEnv({ schema: Env });Entry points
| Entry point | What it adds |
| ------------------------ | ------------------------------------------------------------------- |
| @variablelab/env | defineEnv and schema: the runtime-agnostic core. |
| @variablelab/env/fs | loadConfig, which reads config files on Node, Bun and Deno. |
| @variablelab/env/vite | envConfig(), a Vite plugin. |
| @variablelab/env/react | <EnvScript />, which hydrates the runtime env across SSR and CSR. |
| @variablelab/env/zod | Zod schema primitives, such as port, host and secret. |
Documentation
All of it is at lab.variable.land/env/docs:
- Getting started.
- Concepts: the mental model, the resolution order and env-var naming.
- Guides: recipes for Node, SPA and SSR.
- API reference.
Runnable apps for each runtime are in examples/.
License
The code is MIT. The Sign in brand/ is not: its use is set by BRAND-USE.md.
