Overview
Framework-agnostic typesafe environment variables via Standard Schema.
Framework-agnostic, typesafe environment variables validated with any Standard Schema library (Zod, Valibot, ArkType, and others).
Zero runtime dependencies — install only the validator you use.
Install
pnpm add @g14o/env-core zodPeer dependencies
zod, valibot, and arktype are optional peers — install the validator you use. Ranges follow Standard Schema v1 support on each major line (arktype ^2.0.0, valibot ^1.0.0, zod ^4.0.0).
Usage
import { createEnv } from "@g14o/env-core";
import * as z from "zod";
export const env = createEnv({
clientPrefix: "PUBLIC_",
server: {
DATABASE_URL: z.url(),
OPEN_AI_API_KEY: z.string().min(1),
},
client: {
PUBLIC_API_URL: z.url(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
});On the server, all variables are validated and readable. On the client, only client keys are validated; accessing a server key throws with the exact variable name.
Import the same env object in server and client code — no separate client export is required.
Next steps
- Validators — Zod, Valibot, ArkType examples
- Client vs server — proxy behavior and security
- API reference
Demo
See the env-demo app for a live Zod / Valibot / ArkType showcase.