Skip to content

basalt / env/src / defineEnv

Function: defineEnv() ​

> defineEnv<TShape>(shape, options?): $InferObjectOutput<TShape>

Defined in: env/src/index.ts:106

Validates and types environment variables. Aggregates ALL errors into a single report instead of failing one variable at a time.

export const env = defineEnv({ DATABASE_URL: z.string().url(), PORT: z.coerce.number().default(3000), })

With { prefix: 'MY_SAAS' } each variable is read as MY_SAAS_DATABASE_URL first, falling back to the bare DATABASE_URL.

Type Parameters ​

TShape ​

TShape extends Readonly<{[k: string]: $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; }>

Parameters ​

shape ​

TShape

options? ​

DefineEnvOptions = {}

Returns ​

$InferObjectOutput<TShape>

Released under the MIT License.