getEnv() is the request’s c.env. On Cloudflare that is the Worker bindings object. On Node during vite dev, the Hono adapter exposes .env files on process.env, and the request context still has an env object.
getEnv() in loaders, actions, and middleware so the same code runs on Workers. Do not sprinkle process.env through those files.
Files
Do not put secrets in
vite.config.ts or client pages. The plugin sets Vite’s envPrefix to PUBLIC_, so only import.meta.env.PUBLIC_* is bundled for the browser.
Node vs Workers
On Workers,process.env is not your Wrangler bindings. Bindings only exist on c.env / the env argument of fetch / scheduled / queue / email.
src/worker.ts
getEnv() is that same env. In scheduled / queue / email, pass env yourself — getEnv() is request-scoped and will throw.
Client env
The browser only seesimport.meta.env.PUBLIC_*. Use that for public values such as PUBLIC_APP_URL. Never prefix secrets with PUBLIC_.
Loader and layout data sent to the client (window.__BR_DATA__, SPA JSON navigations) automatically drops fields whose names match non-PUBLIC_ keys on getEnv(). Return only what the page needs, or use pickPublicEnv(getEnv()) when you intentionally expose config:
.env example
.env