```js // @noErrors import { defineEnvVars } from '@sveltejs/kit/env'; ``` ## defineEnvVars Utility for defining [environment variables](/docs/kit/environment-variables), which are made available via `$app/env/public` and `$app/env/private`. ```js // @errors: 7031 import { defineEnvVars } from '@sveltejs/kit/env'; import * as v from 'valibot'; export const variables = defineEnvVars({ API_URL: { schema: v.pipe(v.string(), v.url()) }, PORT: { schema: (value) => { if (value === undefined) return 3000; const port = Number(value); if (!Number.isInteger(port)) throw new Error('PORT must be an integer'); return port; } } }); ```
```dts function defineEnvVars< T extends Record> >(variables: T): DefinedEnvVars; ```
## DefinedEnvVars The return type of [`defineEnvVars`](/docs/kit/@sveltejs-kit-env#defineEnvVars).
```dts type DefinedEnvVars< T extends Record> > = { readonly [K in keyof T]: EnvVarEntry; }; ```
## EnvVarConfig [Environment variables](/docs/kit/environment-variables) can be configured by exporting a `variables` object from `src/env.ts`, using [`defineEnvVars`](/docs/kit/@sveltejs-kit-env#defineEnvVars).
```dts interface EnvVarConfig {/*…*/} ```
```dts public?: boolean; ```
- default `false`
Whether the environment variable can be accessed by client-side code. - if `true`, it can be imported from `$app/env/public` - if `false`, it can be imported from `$app/env/private`, which is a [server-only module](/docs/kit/server-only-modules)
```dts static?: boolean; ```
- default `false`
Whether the value is determined at build time or when the app runs. - if `true`, the build time value is inlined into the bundle. This enables optimisations like dead-code elimination - if `false`, the value is read from the environment when the app starts
```dts schema?: StandardSchemaV1 | ((value: string | undefined) => T | undefined); ```
A [Standard Schema](https://standardschema.dev/) validator that is applied to the value when the app starts. Alternatively, a function that returns the (possibly transformed) value, or throws an error explaining the problem. Returning `undefined` is valid, so a function can describe an optional variable. The validator can output any value — not necessarily a string — but public, non-static values must be serializable by [devalue](https://github.com/sveltejs/devalue) so that they can be sent to the browser. If omitted, the value must be set, but may be an empty string.
```dts description?: string; ```
A description of the variable that will be used for inline documentation on hover.