Skip to main content

Typesafe Env Generator

Generate validated, type-safe environment variable schemas. Add your env vars, choose types, and get both a T3-env createEnv() schema and a plain Zod schema — ready to drop into your Next.js or Node.js project.

✓ T3-env + Zod output ✓ Server & client separation ✓ TypeScript-ready

Add Environment Variable

Variables

No variables added yet.

 

T3-env: npm install @t3-oss/env-nextjs zod. Plain Zod: npm install zod.

Frequently Asked Questions

What is T3-env?▼

T3-env (@t3-oss/env-core, @t3-oss/env-nextjs) is a TypeScript library that validates environment variables at build/runtime using Zod schemas. It provides type-safe access to env vars, catches missing or malformed variables early (at startup, not runtime), and separates server-side from client-side env vars.

Why should I validate environment variables?▼

Missing or malformed env vars are a common source of runtime errors that are hard to debug. Without validation, your app might silently use undefined values or crash with cryptic errors. Zod validation catches these issues at startup with clear error messages, and TypeScript types prevent typos in variable names throughout your codebase.

T3-env vs plain Zod schema — what is the difference?▼

Plain Zod: you call z.object().parse(process.env) yourself, which works but requires manual setup for server/client separation and Next.js compatibility. T3-env: wraps Zod with a createEnv() helper that handles Next.js client prefix rules (NEXT_PUBLIC_), build-time validation, and TypeScript intellisense — less boilerplate for Next.js projects.

How do I validate env vars in Next.js?▼

With @t3-oss/env-nextjs: create env.ts with createEnv({ server: {...}, client: {...}, runtimeEnv: process.env }). Import and use env.DATABASE_URL instead of process.env.DATABASE_URL. Client vars must be prefixed with NEXT_PUBLIC_. The schema runs at build time, so missing vars fail the build rather than failing at runtime.

What Zod types should I use for env vars?▼

z.string() for most values. z.string().url() for URLs. z.string().email() for emails. z.coerce.number() for numeric values (coerces the string from process.env to a number). z.enum(['true','false']).transform(v => v === 'true') or z.string().transform(v => v === 'true') for booleans. All env vars start as strings, so use z.coerce for numbers.

Can I use T3-env outside of Next.js?▼

Yes. Use @t3-oss/env-core for framework-agnostic usage. The API is the same — createEnv({ server: {...}, runtimeEnv: process.env }) — but without Next.js-specific client prefix handling. Works with any Node.js, Bun, or Deno project.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →