TypeScript · Zero dependencies · 2.1 kB
Catch missing env vars before they ship.
Anchor validates your environment variables at build time and infers their types automatically — so a typo never becomes a 2 a.m. production page.
import { defineEnv } from "@anchor/env";
export const env = defineEnv({
DATABASE_URL: url(),
PORT: number().default(3000),
STRIPE_KEY: string().startsWith("sk_"),
});
// ✅ fully typed. validated at build time.12.4kstars
340kweekly installs
68contributors
MITlicensed
Why Anchor
Everything you’d expect. Nothing you wouldn’t.
// how it works
From schema to safety in three steps.
Define your variables once. Anchor validates them at build time and hands you a fully typed object — no generics, no runtime cost.
env.ts
import { defineEnv, string, number, url } from "@anchor/env";
export const env = defineEnv({
DATABASE_URL: url(),
PORT: number().default(3000),
STRIPE_KEY: string().startsWith("sk_"),
});Quickstart
Install it. Define it. Import it.
01
Install
Add Anchor with your package manager of choice.
terminal
npm i @anchor/env02
Define your schema
Describe your environment once, validated at build time.
env.ts
import { defineEnv, url } from "@anchor/env";
export const env = defineEnv({
DATABASE_URL: url(),
});03
Import anywhere
Get a fully typed, validated object — no setup required.
app.ts
import { env } from "./env";
env.DATABASE_URL; // fully typed