Learn how environment variable prefixes work and which variables are exposed to the client.
Environment variable prefixes determine which variables are exposed to the browser and which are kept server-side. The prefix tells Vite and Bini.js how to handle each variable.
| Prefix | Exposed to browser | Read with | Use for |
|---|---|---|---|
| BINI_ | Yes | import.meta.env | Public client config |
| VITE_ | Yes | import.meta.env | Public client config |
| No prefix | No | getEnv / requireEnv | Secrets - server only |
BINI_ and VITE_ prefixes are exposed to the browser by default. Variables without a prefix are never exposed to the client.BINI_ is the default prefix for client-side environment variables in Bini.js. These variables are exposed to the browser via import.meta.env.
BINI_* variables are bundled into your client-side JavaScript. Never put secrets in BINI_* variables.VITE_ is Vite's standard prefix for client-side environment variables. Any variable starting with VITE_ is exposed to the browser.
VITE_* and BINI_* work the same way. Both are exposed to the browser. Choose whichever you prefer.Variables without a prefix are never exposed to the browser. They are only accessible server-side via getEnv(c, key) in API routes.
BINI_* or VITE_* for sensitive data.Client-side variables are accessed via import.meta.env in any component:
The same works in MDX files:
import.meta.env is available in all client-side code including pages, components, and MDX files.Server-side variables are accessed via getEnv(c, key) and requireEnv(c, key) in API routes:
| Access Method | Where | Variables |
|---|---|---|
| import.meta.env | Client components | BINI_, VITE_ |
| getEnv(c, key) | API routes | All variables (including no prefix) |
| requireEnv(c, key) | API routes | All variables (throws if missing) |
Both getEnv and requireEnv read environment variables from the Hono request context, but they behave differently:
| Feature | getEnv(c, key) | requireEnv(c, key) |
|---|---|---|
| Returns | string | undefined | string |
| On missing | Returns undefined | Throws error immediately |
| Use case | Optional configuration with defaults | Required configuration |
| Default pattern | getEnv(c, 'KEY') ?? 'default' | requireEnv(c, 'KEY') |
| Error handling | Manual check for undefined | Try/catch or let it bubble |
| When to use | Feature flags, optional settings | Database URLs, API keys, credentials |
requireEnv for critical configuration that your app cannot function without. Use getEnv with ?? defaults for optional configuration.On failure, requireEnv throws with a descriptive message that is safe to catch and return to the caller:
Read secrets with getEnv and requireEnv.
Read env vars from Hono handlers.
Files under app/api/ map to /api/*.
Deploy to Node, Vercel, Netlify, Cloudflare, or Deno.
Learn how environment variable prefixes work and which variables are exposed to the client.
Environment variable prefixes determine which variables are exposed to the browser and which are kept server-side. The prefix tells Vite and Bini.js how to handle each variable.
| Prefix | Exposed to browser | Read with | Use for |
|---|---|---|---|
| BINI_ | Yes | import.meta.env | Public client config |
| VITE_ | Yes | import.meta.env | Public client config |
| No prefix | No | getEnv / requireEnv | Secrets - server only |
BINI_ and VITE_ prefixes are exposed to the browser by default. Variables without a prefix are never exposed to the client.BINI_ is the default prefix for client-side environment variables in Bini.js. These variables are exposed to the browser via import.meta.env.
BINI_* variables are bundled into your client-side JavaScript. Never put secrets in BINI_* variables.VITE_ is Vite's standard prefix for client-side environment variables. Any variable starting with VITE_ is exposed to the browser.
VITE_* and BINI_* work the same way. Both are exposed to the browser. Choose whichever you prefer.Variables without a prefix are never exposed to the browser. They are only accessible server-side via getEnv(c, key) in API routes.
BINI_* or VITE_* for sensitive data.Client-side variables are accessed via import.meta.env in any component:
The same works in MDX files:
import.meta.env is available in all client-side code including pages, components, and MDX files.Server-side variables are accessed via getEnv(c, key) and requireEnv(c, key) in API routes:
| Access Method | Where | Variables |
|---|---|---|
| import.meta.env | Client components | BINI_, VITE_ |
| getEnv(c, key) | API routes | All variables (including no prefix) |
| requireEnv(c, key) | API routes | All variables (throws if missing) |
Both getEnv and requireEnv read environment variables from the Hono request context, but they behave differently:
| Feature | getEnv(c, key) | requireEnv(c, key) |
|---|---|---|
| Returns | string | undefined | string |
| On missing | Returns undefined | Throws error immediately |
| Use case | Optional configuration with defaults | Required configuration |
| Default pattern | getEnv(c, 'KEY') ?? 'default' | requireEnv(c, 'KEY') |
| Error handling | Manual check for undefined | Try/catch or let it bubble |
| When to use | Feature flags, optional settings | Database URLs, API keys, credentials |
requireEnv for critical configuration that your app cannot function without. Use getEnv with ?? defaults for optional configuration.On failure, requireEnv throws with a descriptive message that is safe to catch and return to the caller:
Read secrets with getEnv and requireEnv.
Read env vars from Hono handlers.
Files under app/api/ map to /api/*.
Deploy to Node, Vercel, Netlify, Cloudflare, or Deno.