Ensure that all required environment variables exist.
- ✅ Define required environment variables
- 🔒 Fails fast in dev or build if any are missing
- ⚙️ Checks both .env and runtimeConfig
- 🛠 Improves deployment safety and DX
Install the module to your Nuxt application with one command:
npx nuxi module add nuxt-required-env
Create a file called env-schema.ts in your project root:
import { z } from 'zod'
export const EnvSchema = z.object({
NUXT_PUBLIC_SITE_URL: z.string().url(),
STRIPE_KEY: z.string(),
SUPABASE_URL: z.string().url(),
MY_SECRET: z.string().min(10),
})
If your schema is in a different path, set it via module options:
export default defineNuxtConfig({
modules: ['nuxt-required-env'],
requiredEnv: {
schemaPath: 'config/env-schema', // path relative to project root, without extension
},
})
That's it! You can now use nuxt-required-envin your Nuxt app ✨
Local development
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release