envobject has helpers to read values from the environment:
requiredhelpers are designed for everything that needs to be configured in production. If something is missing, its behaviour depends on NODE_ENV:
SomeModule is not configured. Missing environment variables: SOME_MODULE_URL, SOME_MODULE_SECRET
devFallbackargument. If there is no
devFallbackspecified, it logs a warning and keeps running with a partial configuration (
isConfigured === false).
optionalhelpers are designed for optional configuration which you might have good defaults for.
*JSONvariants try to parse the environment variable as JSON. This is very handy for boolean/numerical environment variables or more complex configuration. If you ever use these helpers, you should specify the expected types using the Zod schema. Any JSON parsing issues are logged as error before crashing the process (with
ConfigTypeinterface you get a strongly typed configuration object.
env.requiredhelpers, you can provide a Zod schema which validates the final object.
serverSideFeatureis set, the config module is only loaded if the specified feature is turned on. Alternatively, the configuration object only has its
isConfiguredattribute set to false.