Skip to main content
A GatoJS app validates its environment with Zod before it serves the first request. A missing or malformed variable stops the server with a report that lists every problem. This page covers how validation works and lists every variable, from the core, from kit modules and from outside the schema.

Quick start

.env.example lists every variable the schema knows (except NODE_ENV). When you create a project, the CLI copies it to .env, generates a random BETTER_AUTH_SECRET and fills in ADMIN_EMAIL if you gave one.
.env.example
The block between # wa:modules:start and # wa:modules:end is generated (see Module variables). The placeholder names (wa_app, WA App) are replaced with your project’s names at creation time.
gato add updates .env.example but not .env. After adding a module, copy its new variables from the wa:modules region into .env and set real values, or the server may refuse to start. After gato remove, delete them from .env and from your production variables.

How validation works

The env layer is the @gatojs/env workspace package (packages/env). It exports the core schema coreEnvSchema and helpers to check it together with module schemas: The generator ties the package to your modules: src/modules.generated.ts ends with export const env = createEnv(moduleEnvSchemas). App code imports it from the stable path:

At startup

Next.js calls register() in src/instrumentation.ts when the server starts. In the Node.js runtime it checks the whole environment, core and installed modules, before anything else:
src/instrumentation.ts
With valid variables it prints nothing. Otherwise it writes a report to stderr and exits with code 1. A standalone server started with no variables at all prints:
The header reads “Invalid environment variables (6)”. Messages come from Zod (English) or from the kit’s own rules (Polish). The last two lines come from the api-keys and uploads modules. Things to know about the report:
  • It goes to the console, not the logger, so you see it in container logs even without OTLP export.
  • ✓ Ready doesn’t mean the env is valid. Next.js prints its banner before the report.
  • A bad module variable stops the whole app, not just that module.
  • Production rules may surface one round at a time. Zod checks a schema’s cross-field refinements (such as “RESEND_API_KEY required in production”) only after the schema’s basic field rules pass. Fixing one batch of errors can reveal the next.

When there is no startup check

  • next build doesn’t call register(), so npm run build succeeds without a .env. verifyEnvOnStartup also skips itself when NEXT_PHASE is phase-production-build.
  • The Edge runtime. register() returns early unless NEXT_RUNTIME is nodejs.
  • Scripts and tests. Vitest, npm run admin:create and other scripts don’t run register(); their variables are checked on the first read of env.
Because env is lazy, importing it never throws. In unit tests, mock the module instead:
The parsed env is cached for the life of the process. Restart the dev server, or redeploy, after changing a variable.

Parsing rules

Core variables

These come from coreEnvSchema and exist in every project.
In production the schema rejects BETTER_AUTH_SECRET (and API_KEY_PEPPER) when they still hold the sample value from .env.example. Generate fresh values per environment.

Module variables

A feature can ship src/features/<name>/env.ts exporting a Zod envSchema. The generator adds it to moduleEnvSchemas, and checkEnv combines it with the core schema through z.intersection. Errors from both end up in the same startup report. The lines in the wa:modules region of .env.example come from a different place: the env field of each module’s manifest in .wa/kit.json. The generator doesn’t compare the two lists, so a variable checked by envSchema may be missing from .env.example. The core’s own variables are written into .env.example outside the region.
env is typed as CoreEnv, so env.MY_MODULE_VAR is a TypeScript error (TS2339) even though the value is present at runtime. The kit has no built-in typed accessor for feature variables yet.

api-keys

See API keys.

uploads

With local in production on Railway, a service without a volume fails with na Railway bez wolumenu pliki zginą przy redeployu (“on Railway without a volume files will be lost on redeploy”). See File storage and Uploads.

Variables outside the schema

These are read directly by code, configuration or libraries. They are not in .env.example and are not validated.

Variables read without validation

Outside the Next.js server (which always runs the startup check), validation only protects reads through env. A few schema variables are read directly from process.env:
  • DATABASE_URL in src/shared/lib/prisma.ts and prisma.config.ts. Prisma CLI commands such as migrate deploy work without the other variables.
  • NODE_ENV and OTEL_EXPORTER_OTLP_ENDPOINT in the logger and instrumentation.ts.
  • ADMIN_EMAIL and ADMIN_PASSWORD in scripts/admin-create.ts.

Deploy on Railway

What to set in production, step by step.

Logging and observability

OTLP export, the logger and the healthcheck.