Nuxt
Learn how to use ArkEnv in a Nuxt project.
@arkenv/nuxt validates environment variables on server and client
routes, maps public keys onto Nuxt runtime config, and keeps server
secrets off the browser.
For high-level architectural trade-offs, see Frameworks.
Quickstart
Scaffold Nuxt integration in an existing project using the CLI:
npx arkenv initpnpm dlx arkenv inityarn dlx arkenv initbunx arkenv initThe CLI registers @arkenv/nuxt/module in your Nuxt config and creates your initial
schema file.
Manual installation
If you prefer manual setup, install @arkenv/nuxt alongside your chosen
validation engine.
ArkType engine
Install @arkenv/core and its peer dependency arktype:
npm install @arkenv/core @arkenv/nuxt arktypepnpm add @arkenv/core @arkenv/nuxt arktypeyarn add @arkenv/core @arkenv/nuxt arktypebun install @arkenv/core @arkenv/nuxt arktypeStandard Schema engine
If you aren't using ArkType, install @arkenv/standard:
npm install @arkenv/standard @arkenv/nuxtpnpm add @arkenv/standard @arkenv/nuxtyarn add @arkenv/standard @arkenv/nuxtbun install @arkenv/standard @arkenv/nuxtModule configuration
Register the module in your nuxt.config.ts. The module automatically injects
runtime configuration and validates variables during build and development.
export default defineNuxtConfig({
modules: ["@arkenv/nuxt/module"],
});Schema
Use a single env.ts. Public keys must use the NUXT_PUBLIC_ prefix:
import from "@arkenv/nuxt";
export const = ({
: "string",
: "string = 'https://api.example.com'",
: "'development' | 'production' | 'test' = 'development'",
});Unlike Next.js, Nuxt does not emit an env.gen.ts file; @arkenv/nuxt acts as
the primary entrypoint.
If you split client and server modules for name/type isolation, never import the server module from client or Vue code. See the two-module recipe.
Read env in application code
Import { env } from "./env".
Do not read process.env directly
Reading process.env skips ArkEnv. Import { env } so public keys stay
typed and coerced and server secrets stay out of the client bundle.
Standard Schema
If you aren't using ArkType, point the module at the standard module path and
import from @arkenv/nuxt/standard:
export default defineNuxtConfig({
modules: ["@arkenv/nuxt/standard/module"],
});Then define your schema in env.ts using your validator:
import from "@arkenv/nuxt/standard";
import * as from "zod";
export const = ({
: .(),
: .().("https://api.example.com"),
});Nitro boot gate and runtimeConfig hydration
Containers in staging and production inject environment variables at startup rather than at build time.
Vite and Bun inline literals at build time through compile-time transforms. @arkenv/nuxt hooks into Nuxt's Nitro engine instead:
- Server boot gate: At server startup, an internal Nitro plugin runs before route handlers execute. It validates the environment against your schema and throws fail-fast errors on invalid secrets.
- Runtime configuration hydration: An internal Nitro plugin passes validated public variables (
NUXT_PUBLIC_*) intouseRuntimeConfig().public. - Client access: Client components read public values from runtime configuration during browser rendering and hydration, avoiding hardcoded build-time literals.
You can update environment variables across deployment stages without rebuilding client JavaScript bundles. Ship one image and change env at container start for staging versus production.
Unlike Next.js env.gen.ts, @arkenv/nuxt writes no generated files to
commit or gitignore. The module validates at boot and registers public
keys on runtimeConfig.