How do you manage environment variables in SvelteKit?

Answer

SvelteKit has a built-in environment variable system with strict client/server separation. $env/static/private: server-only environment variables available at build time. Import: import { DATABASE_URL } from '$env/static/private';. These are replaced with their values at build time and never sent to the browser. $env/static/public: public variables (must be prefixed PUBLIC_ in .env) available everywhere. $env/dynamic/private: server-only variables evaluated at runtime (not build time). Required for serverless deployments where env vars might change per environment. $env/dynamic/public: runtime public variables. SvelteKit prevents private variables from being imported in client code — it throws a build error. Define variables in .env, .env.local, or deployment platform. VITE_ prefix: variables prefixed with VITE_ are exposed to client-side Vite code but use PUBLIC_ prefix for SvelteKit's module system.