nuxt-required-env
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

nuxt-required-env

npm version npm downloads License Nuxt

Ensure that all required environment variables exist.

Features

  • ✅ Define required environment variables
  • 🔒 Fails fast in dev or build if any are missing
  • ⚙️ Checks both .env and runtimeConfig
  • 🛠 Improves deployment safety and DX

Quick Setup

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 ✨

Contribution

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

Readme

Keywords

none

Package Sidebar

Install

npm i nuxt-required-env

Weekly Downloads

201

Version

1.0.8

License

MIT

Unpacked Size

9.32 kB

Total Files

10

Last publish

Collaborators

  • criting