Skip to main content
next-safe-env ships a CLI you can run with npx - no install required.

check - validate before you deploy

Validates the current environment against your schema without starting the app. Useful in CI pipelines to gate deployments before they reach production.

Arguments

Exit codes

The command imports your env file in an isolated child process. Because createEnv runs at import time, any validation failure triggers the same formatted error output you’d see at startup - then the process exits with code 1.

Examples

Sample output on failure

check imports your compiled .js file - not the .ts source. Build your project first (npm run build) or use a TypeScript runner like tsx:

init - interactive scaffold

Generates src/env.ts and .env.example by asking which variables your app needs and what type each one should be.

Options

What it asks

  1. Framework - auto-detected from package.json (checks for next, vite, @cloudflare/workers-types, etc.). If detected, you’re asked to confirm; if not, you choose from Next.js, Node.js, Vite, or Edge Runtime. The framework determines the adapter and client-var prefix.
  2. Server-side variables - name, type, optional flag, default value, and (for str) allowed values
  3. Client-side variables - same prompts; variable names are auto-prefixed (NEXT_PUBLIC_ or VITE_) if you omit the prefix
  4. Output file path
  5. Whether to generate .env.example

Example session

If the adapter cannot be auto-detected, the framework menu is shown instead:

Generated src/app/env.ts


.env.example generation

Running init with the .env.example prompt answered y produces a commented template alongside src/env.ts. Each variable gets an inline comment describing its type, whether it is required, any constraints, and its default value - so new contributors know exactly what to fill in.

Example .env.example