> ## 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: Typed, validated environment variables

> next-safe-env validates and types env variables for Next.js, Node.js, Edge, and Vite. Zero dependencies, under 5 kB. Fails at startup, never at runtime.

<div align="center">
  <img src="https://raw.githubusercontent.com/mzeeshanwahid/next-safe-env/main/assets/logo-nobg.png" width="400" alt="next-safe-env logo" noZoom />
</div>

`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.

<CardGroup cols={2}>
  <Card title="Quick Start" icon="rocket" href="/quickstart">
    Install next-safe-env and validate your first environment variable in minutes.
  </Card>

  <Card title="Next.js Guide" icon="layer-group" href="/guides/nextjs">
    Set up server/client env splitting with automatic NEXT\_PUBLIC\_ enforcement.
  </Card>

  <Card title="All Validators" icon="shield-check" href="/api/validators">
    Explore str, num, bool, url, port and their chainable validation rules.
  </Card>

  <Card title="createEnv Reference" icon="code" href="/api/create-env">
    Full reference for every option accepted by the createEnv() function.
  </Card>
</CardGroup>

## 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.

<CardGroup cols={2}>
  <Card title="Node.js Guide" icon="node-js" href="/guides/nodejs">
    Use next-safe-env in any Node.js server, API, or script.
  </Card>

  <Card title="Edge Runtime Guide" icon="bolt" href="/guides/edge-runtime">
    Validate env vars in Vercel Edge Runtime and Next.js Middleware.
  </Card>

  <Card title="Zod Interop" icon="puzzle-piece" href="/guides/zod-interop">
    Pass z.object() schemas directly if your project already uses Zod.
  </Card>

  <Card title="Testing" icon="flask" href="/guides/testing">
    Skip validation in test environments without removing your schema.
  </Card>
</CardGroup>

<Steps>
  <Step title="Install">
    ```bash theme={null}
    npm install next-safe-env
    ```
  </Step>

  <Step title="Define your schema">
    Create `src/env.ts` with your server and client variable definitions.
  </Step>

  <Step title="Import and use">
    Import `env` anywhere in your project and get fully-typed, validated values.
  </Step>
</Steps>
