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
# 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.
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 callsregister() 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
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.
✓ Readydoesn’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_KEYrequired 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 builddoesn’t callregister(), sonpm run buildsucceeds without a.env.verifyEnvOnStartupalso skips itself whenNEXT_PHASEisphase-production-build.- The Edge runtime.
register()returns early unlessNEXT_RUNTIMEisnodejs. - Scripts and tests. Vitest,
npm run admin:createand other scripts don’t runregister(); their variables are checked on the first read ofenv.
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 fromcoreEnvSchema and exist in every project.
Module variables
A feature can shipsrc/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 throughenv. A few schema variables are read directly from process.env:
DATABASE_URLinsrc/shared/lib/prisma.tsandprisma.config.ts. Prisma CLI commands such asmigrate deploywork without the other variables.NODE_ENVandOTEL_EXPORTER_OTLP_ENDPOINTin the logger andinstrumentation.ts.ADMIN_EMAILandADMIN_PASSWORDinscripts/admin-create.ts.
Related
Deploy on Railway
What to set in production, step by step.
Logging and observability
OTLP export, the logger and the healthcheck.