Environment Variables
srvkit supports deferred environment variables — values that are resolved at runtime instead of being hardcoded at build time. This lets you configure different options from environment variables without embedding them in the output bundle.
How It Works
srvkit uses Envkist under the hood. In development, env references resolve immediately by reading process.env etc. In production, they are injected as runtime-appropriate code that reads the environment variable when the server starts.
Usage
Import env from the plugin entry:
env.string
Creates a resolvable string value that reads from an environment variable:
env.number
Creates a resolvable number value that reads from an environment variable:
With Fallback Values
Pass a second argument to set a default when the environment variable is not set:
Static Values
You can still use plain strings and numbers — they are fully supported alongside env references:
Supported Options
The following options accept either a static value or an env reference:
Runtime Behavior
In production builds, srvkit injects runtime-specific code for reading environment variables based on the runtime option:
When targeting workerd (Cloudflare Workers), srvkit automatically injects import { env } from "cloudflare:workers" into the output entry.