Config validation
Think of it like… a pre-flight checklist. Instead of taking off and discovering the fuel gauge is broken at 30,000 feet, you catch every problem on the ground — and you get the whole list at once, not one redeploy at a time.
defineConfig() is a single boot-time helper that loads your application configuration from a source you choose, validates the merged object against a Standard Schema validator (Zod, Valibot, ArkType, TypeBox, and others), and aggregates every validation issue into one structured error printed to stderr before the process exits.
The point is to fail fast and loud: a misconfigured deployment should surface every missing or invalid key in one shot, so operators do not have to redeploy four times to discover four different typos.
Quick start (from the environment)
By default defineConfig() reads from process.env. The result is fully typed from your schema.
If any key is missing or malformed, the process prints a summary and throws before your server ever binds a port:
Choosing a source
The source option selects where the raw object comes from. The built-in sources are intentionally narrow; anything more elaborate (Vault, Doppler, AWS Secrets Manager) arrives through the custom source with an async resolver.
Transforming before validation
Use transform to coerce or rename raw values before they hit the schema — for example mapping FOO_BAR to fooBar, or normalizing string flags. It receives the raw source object and returns the object handed to the validator.
Handling the error programmatically
On failure, defineConfig() throws a ConfigValidationError whose issues array holds every { key, message } pair. Catch it when you want to render the failures in a startup probe or dashboard instead of relying on the stderr summary.
The stderr summary is on by default. Set stderr: false to suppress the printed output; the thrown ConfigValidationError still carries issues.