Environment variable system for Bini.js. Hono-native, works on every runtime.
bini-env reads environment variables from the Hono request context, so they always resolve from the correct runtime binding - Node.js, Bun, Deno, Vercel Edge, Netlify Edge, or Cloudflare Workers - without any per-platform code.
hono >= 4.0.0 - required peer dependency>= 8.0.0 - optional peer, only needed for the Vite plugin>= 20.12.0The package has three entry points:
| Import | Contents | Runs on |
|---|---|---|
| bini-env | getEnv, requireEnv, checkEnv, requireEnvs, biniLogger, and types | Any runtime |
| bini-env/vite | biniEnv() | Node, inside Vite |
| bini-env/node | loadEnvFiles, envFilesFor | Node |
biniEnv() takes no options.
When the dev or preview server starts, it prints the detected .env files:
Two prefixes are exposed to the browser: BINI_ and VITE_. Everything else stays server-side.
| Prefix | Exposed to browser | Use for |
|---|---|---|
| No prefix | Never | Secrets - API keys, database URLs, tokens |
| BINI_ | Yes | Public config |
| VITE_ | Yes | Public config (Vite default) |
Pass the Hono context c to getEnv and requireEnv and they resolve from the correct source on every platform:
| Platform | Runtime | Env source |
|---|---|---|
| Node.js | Node | process.env |
| Bun | Bun | process.env |
| Vercel Edge | V8 isolate | process.env |
| Netlify Edge | Deno | Deno.env.get() |
| Cloudflare Workers | V8 isolate | c.env |
| Deno Deploy | Deno | Deno.env.get() |
Returns string | undefined. Use for optional config. An empty value is returned as an empty string, so ?? does not fall back for it.
Returns string. Throws if the variable is missing, empty, or not a string. Use for required config.
Checks several variables at once. Returns { ok, missing }. Does not throw - logs one error listing every missing name.
Requires several variables at once. Returns a record of key to value. Throws one error listing every missing name.
Terminal logger with Vite-style timestamps, for your own server-side code.
Loads .env files into process.env without Vite. Imported from bini-env/node. Priority order: .env.[mode].local, .env.[mode], .env.local, .env. Existing environment values always win.
| Type | Definition |
|---|---|
| HonoContext | Hono's Context |
| EnvSource | Record<string, unknown> |
| EnvInput | HonoContext | EnvSource | undefined | null |
| EnvCheck | { ok: boolean; missing: string[] } |
Environment variable system for Bini.js. Hono-native, works on every runtime.
bini-env reads environment variables from the Hono request context, so they always resolve from the correct runtime binding - Node.js, Bun, Deno, Vercel Edge, Netlify Edge, or Cloudflare Workers - without any per-platform code.
hono >= 4.0.0 - required peer dependency>= 8.0.0 - optional peer, only needed for the Vite plugin>= 20.12.0The package has three entry points:
| Import | Contents | Runs on |
|---|---|---|
| bini-env | getEnv, requireEnv, checkEnv, requireEnvs, biniLogger, and types | Any runtime |
| bini-env/vite | biniEnv() | Node, inside Vite |
| bini-env/node | loadEnvFiles, envFilesFor | Node |
biniEnv() takes no options.
When the dev or preview server starts, it prints the detected .env files:
Two prefixes are exposed to the browser: BINI_ and VITE_. Everything else stays server-side.
| Prefix | Exposed to browser | Use for |
|---|---|---|
| No prefix | Never | Secrets - API keys, database URLs, tokens |
| BINI_ | Yes | Public config |
| VITE_ | Yes | Public config (Vite default) |
Pass the Hono context c to getEnv and requireEnv and they resolve from the correct source on every platform:
| Platform | Runtime | Env source |
|---|---|---|
| Node.js | Node | process.env |
| Bun | Bun | process.env |
| Vercel Edge | V8 isolate | process.env |
| Netlify Edge | Deno | Deno.env.get() |
| Cloudflare Workers | V8 isolate | c.env |
| Deno Deploy | Deno | Deno.env.get() |
Returns string | undefined. Use for optional config. An empty value is returned as an empty string, so ?? does not fall back for it.
Returns string. Throws if the variable is missing, empty, or not a string. Use for required config.
Checks several variables at once. Returns { ok, missing }. Does not throw - logs one error listing every missing name.
Requires several variables at once. Returns a record of key to value. Throws one error listing every missing name.
Terminal logger with Vite-style timestamps, for your own server-side code.
Loads .env files into process.env without Vite. Imported from bini-env/node. Priority order: .env.[mode].local, .env.[mode], .env.local, .env. Existing environment values always win.
| Type | Definition |
|---|---|
| HonoContext | Hono's Context |
| EnvSource | Record<string, unknown> |
| EnvInput | HonoContext | EnvSource | undefined | null |
| EnvCheck | { ok: boolean; missing: string[] } |