Skip to main content

Documentation Index

Fetch the complete documentation index at: https://next-safe-env.dev/llms.txt

Use this file to discover all available pages before exploring further.

next-safe-env logo
next-safe-env gives you fully-typed, validated environment variables in Next.js, Node.js, Edge Runtime, and Vite projects - with zero runtime dependencies and a bundle footprint under 5 kB. Instead of scattering manual process.env checks across your codebase, you define a schema once and the library crashes loudly at startup if anything is missing or malformed.

Quick Start

Install next-safe-env and validate your first environment variable in minutes.

Next.js Guide

Set up server/client env splitting with automatic NEXT_PUBLIC_ enforcement.

All Validators

Explore str, num, bool, url, port and their chainable validation rules.

createEnv Reference

Full reference for every option accepted by the createEnv() function.

Why next-safe-env?

process.env.X is always string | undefined in TypeScript - no autocomplete, no validation, and silent undefined failures at runtime. next-safe-env fixes this with a single function call.

Node.js Guide

Use next-safe-env in any Node.js server, API, or script.

Edge Runtime Guide

Validate env vars in Vercel Edge Runtime and Next.js Middleware.

Zod Interop

Pass z.object() schemas directly if your project already uses Zod.

Testing

Skip validation in test environments without removing your schema.
1

Install

npm install next-safe-env
2

Define your schema

Create src/env.ts with your server and client variable definitions.
3

Import and use

Import env anywhere in your project and get fully-typed, validated values.