Standard environment variable handling for Bini.js - works across Node.js, Bun, Deno, Vercel Edge, Netlify Edge, and Cloudflare Workers.
Bini.js uses standard environment variable handling across the client and server. On the client, variables are accessed through import.meta.env. In API routes, they are read from the Hono request context via c.env, ensuring they resolve correctly from the host platform (Node.js, Bun, Deno, Cloudflare, etc.) with no platform-specific code.
.env files are loaded automatically. Secrets are available in your API routes via c.env without any extra setup.Bini.js is configured out of the box. Just start using the environment variables in your routes.
.env with no prefix. In production, set it in your hosting platform's dashboard.Access environment variables directly from the Hono context c.env. This ensures they are request-scoped and correctly resolved for your runtime.
The pattern in three steps:
c.env.KEY for vars the handler cannot run without.c.env.KEY ?? 'default' for optional vars with sensible defaults.KEY=) is returned as '', so ?? does not fall back. Check for it explicitly if you rely on a fallback.Vite loads .env files from your project root. The prefix of each variable decides where it ends up.
BINI_ variables are exposed to import.meta.env. Use them for public client-side config.
VITE_ is Vite's built-in prefix. Any var starting with VITE_ is bundled into your client-side JavaScript.
Variables without a prefix are NOT exposed to the browser. They are read via c.env in API routes. During dev and preview they are also mirrored into process.env automatically.
| Prefix | Exposed to browser | Mirrored to process.env (dev/preview) | Use for |
|---|---|---|---|
| BINI_ | Yes | Yes (unless already set) | Public client config |
| VITE_ | Yes | Yes (unless already set) | Public client config |
| No prefix | No | Yes (unless already set) | Secrets - server only |
BINI_* or VITE_* variables - both are exposed to the browser. Use un-prefixed variables for secrets and read them via c.env inside API route handlers only.On the client, use import.meta.env for public variables. In API routes, use c.env to read from the runtime bindings.
| Environment | Access Method | Behavior |
|---|---|---|
| Client | import.meta.env.KEY | Bundled at build time. Only BINI_ and VITE_ prefixes. |
| API Routes | c.env.KEY | Runtime bindings. All variables, including secrets. |
An empty value (API_KEY=) is still treated as configured by the runtime, but you should check for it explicitly in your handler to fail fast:
| Problem | Solution |
|---|---|
| Env var undefined in production | Set variables in your hosting platform env dashboard (Vercel, Netlify, Cloudflare, etc.). |
| Works in dev, undefined in prod | Local dev works because .env files are loaded automatically. Production requires platform-level configuration. |
| c.env is undefined | Ensure you are passing the Hono context c directly to your route handlers. |
| getEnv returned an empty string instead of my default | An empty .env value is returned as '', and ?? only falls back for undefined. Check for it explicitly or remove the empty line. |
| Cloudflare secret not found | Secrets set via wrangler secret put are only available via c.env. Ensure you are passing c to the function. |
| Types not found | Add /// <reference types="vite/client" /> to your tsconfig.json or entry file. |
What gets bundled and what stays server-side.
Read env vars from Hono handlers.
Files under app/api/ map to /api/*.
Deploy to Node, Vercel, Netlify, Cloudflare, or Deno.
Standard environment variable handling for Bini.js - works across Node.js, Bun, Deno, Vercel Edge, Netlify Edge, and Cloudflare Workers.
Bini.js uses standard environment variable handling across the client and server. On the client, variables are accessed through import.meta.env. In API routes, they are read from the Hono request context via c.env, ensuring they resolve correctly from the host platform (Node.js, Bun, Deno, Cloudflare, etc.) with no platform-specific code.
.env files are loaded automatically. Secrets are available in your API routes via c.env without any extra setup.Bini.js is configured out of the box. Just start using the environment variables in your routes.
.env with no prefix. In production, set it in your hosting platform's dashboard.Access environment variables directly from the Hono context c.env. This ensures they are request-scoped and correctly resolved for your runtime.
The pattern in three steps:
c.env.KEY for vars the handler cannot run without.c.env.KEY ?? 'default' for optional vars with sensible defaults.KEY=) is returned as '', so ?? does not fall back. Check for it explicitly if you rely on a fallback.Vite loads .env files from your project root. The prefix of each variable decides where it ends up.
BINI_ variables are exposed to import.meta.env. Use them for public client-side config.
VITE_ is Vite's built-in prefix. Any var starting with VITE_ is bundled into your client-side JavaScript.
Variables without a prefix are NOT exposed to the browser. They are read via c.env in API routes. During dev and preview they are also mirrored into process.env automatically.
| Prefix | Exposed to browser | Mirrored to process.env (dev/preview) | Use for |
|---|---|---|---|
| BINI_ | Yes | Yes (unless already set) | Public client config |
| VITE_ | Yes | Yes (unless already set) | Public client config |
| No prefix | No | Yes (unless already set) | Secrets - server only |
BINI_* or VITE_* variables - both are exposed to the browser. Use un-prefixed variables for secrets and read them via c.env inside API route handlers only.On the client, use import.meta.env for public variables. In API routes, use c.env to read from the runtime bindings.
| Environment | Access Method | Behavior |
|---|---|---|
| Client | import.meta.env.KEY | Bundled at build time. Only BINI_ and VITE_ prefixes. |
| API Routes | c.env.KEY | Runtime bindings. All variables, including secrets. |
An empty value (API_KEY=) is still treated as configured by the runtime, but you should check for it explicitly in your handler to fail fast:
| Problem | Solution |
|---|---|
| Env var undefined in production | Set variables in your hosting platform env dashboard (Vercel, Netlify, Cloudflare, etc.). |
| Works in dev, undefined in prod | Local dev works because .env files are loaded automatically. Production requires platform-level configuration. |
| c.env is undefined | Ensure you are passing the Hono context c directly to your route handlers. |
| getEnv returned an empty string instead of my default | An empty .env value is returned as '', and ?? only falls back for undefined. Check for it explicitly or remove the empty line. |
| Cloudflare secret not found | Secrets set via wrangler secret put are only available via c.env. Ensure you are passing c to the function. |
| Types not found | Add /// <reference types="vite/client" /> to your tsconfig.json or entry file. |
What gets bundled and what stays server-side.
Read env vars from Hono handlers.
Files under app/api/ map to /api/*.
Deploy to Node, Vercel, Netlify, Cloudflare, or Deno.