Discriminator
The discriminator determines which defaults to use. Defaults to NODE_ENV when not specified.
Note:
NODE_ENVis a Node.js runtime concern — libraries like React and Express change behavior based on its value, and it’s conventionally limited todevelopment,production, andtest. For selecting environment-specific defaults (local dev URLs, staging credentials, etc.), a dedicated variable likeAPP_ENVis a better fit. You can haveNODE_ENV=productionin both staging and production while usingAPP_ENVto distinguish between them.
export default defineConfig({ schema: z.object({ APP_ENV: z.enum(["local", "staging", "prod"]), API_URL: z.string().url(), }), discriminator: "APP_ENV", defaults: { local: { API_URL: "http://localhost:4000", }, staging: { API_URL: "https://staging.api.example.com", }, prod: { API_URL: "https://api.example.com", }, },});