$env/dynamic/private
This module provides access to environment variables set dynamically at runtime and that are limited to private access.
| Runtime | Build time | |
|---|---|---|
| Private | $env/dynamic/private |
$env/static/private |
| Public | $env/dynamic/public |
$env/static/public |
Dynamic environment variables are defined by the platform you're running on. For example if you're using adapter-node (or running vite preview), this is equivalent to process.env.
Private access:
- This module cannot be imported into client-side code
- This module includes variables that do not begin with
config.kit.env.publicPrefixand do start withconfig.kit.env.privatePrefix(if configured)
In
dev,$env/dynamicincludes environment variables from.env. Inprod, this behavior will depend on your adapter.
To get correct types, environment variables referenced in your code should be declared (for example in an
.envfile), even if they don't have a value until the app is deployed:MY_FEATURE_FLAG=You can override
.envvalues from the command line like so:MY_FEATURE_FLAG="enabled" npm run dev
For example, given the following runtime environment:
ENVIRONMENT=production
PUBLIC_BASE_URL=http://site.comWith the default publicPrefix and privatePrefix:
import { import envenv } from '$env/dynamic/private';
var console: Consoleconsole.Console.log(...data: any[]): voidlog(import envenv.ENVIRONMENT); // => "production"
var console: Consoleconsole.Console.log(...data: any[]): voidlog(import envenv.PUBLIC_BASE_URL); // => undefinedEdit this page on GitHub llms.txt