Introduction
Validate and secure your Next.js environment variables with zero-boilerplate scaffolding and a seamless developer experience.
This integration requires ArkType to be installed.
The @arkenv/nextjs integration provides end-to-end environment validation for both the server and the browser. It catches configuration bugs early in your build pipeline and prevents sensitive server-side variables from ever reaching client components.
Quickstart
The fastest way to get started is with the ArkEnv CLI. It automatically configures @arkenv/nextjs for your existing Next.js project.
npx @arkenv/cli@latest initpnpm dlx @arkenv/cli@latest inityarn dlx @arkenv/cli@latest initbunx @arkenv/cli@latest initLayout strategies
ArkEnv supports two layout structures to match your security and developer experience preferences:
Flat layout (recommended)
Define client and server variables in a single flat schema file (src/env.ts) for the best developer experience (DX).
Strict layout
Separate client and server schemas into different files to prioritize strict compile-time security.
Next steps
Zod, Valibot, and other Standard Schema validators
Learn how to mix and match ArkType with other Standard Schema validators in Next.js.
FAQ
Find answers to frequently asked questions about @arkenv/nextjs, including the danger of custom shared variables.
Next.js Environment Variables Guide
Read the official Next.js documentation on how environment variables are loaded and exposed.