Skip to main content

$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:

In dev, $env/dynamic includes environment variables from .env. In prod, this behavior will depend on your adapter.

To get correct types, environment variables referenced in your code should be declared (for example in an .env file), even if they don't have a value until the app is deployed:

MY_FEATURE_FLAG=

You can override .env values 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.com

With 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); // => undefined

Edit this page on GitHub llms.txt