DocsPluginsShowcaseReleases
npmStar us on GitHub
overviewcreate-bini-appbini-deploybini-routerbini-envbini-nativebini-serverbini-overlaybini-ssgvite plugins↗hono plugins↗

A native React framework for building cross-platform applications from a single codebase.

Resources

  • Documentation
  • Plugins
  • Showcase
  • Releases

Community

  • GitHub Discussions
  • Reddit
  • Discord
  • LinkedIn

More

  • npm
  • GitHub
  • Issues
  • License

© 2026 Bini Cooperation.

bini-env

Official

Environment variable system for Bini.js. Hono-native, works on every runtime.

Overview

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 handlergetEnv(c,key)
dev.envprodplatform env

Requirements

  • hono >= 4.0.0 - required peer dependency
  • Vite >= 8.0.0 - optional peer, only needed for the Vite plugin
  • Node.js >= 20.12.0

Install

>_Terminal
$ npm install bini-env hono

The package has three entry points:

ImportContentsRuns on
bini-envgetEnv, requireEnv, checkEnv, requireEnvs, biniLogger, and typesAny runtime
bini-env/vitebiniEnv()Node, inside Vite
bini-env/nodeloadEnvFiles, envFilesForNode

Quick Start

1. Register the Vite plugin

vite.config.ts
import { defineConfig } from 'vite'
import { biniEnv } from 'bini-env/vite'

export default defineConfig({
  plugins: [biniEnv()],
})

biniEnv() takes no options.

2. Read env vars in a Hono handler

src/app/api/hello.ts
import { Hono } from 'hono'
import { getEnv, requireEnv } from 'bini-env'

const app = new Hono()

app.post('/hello', async (c) => {
  try {
    // requireEnv throws if the var is missing or empty
    const apiKey = requireEnv(c, 'MY_API_KEY')

    // getEnv returns undefined if the var is missing
    const appName = getEnv(c, 'APP_NAME') ?? 'World'

    return c.json({ message: `Hello, ${appName}!` })
  } catch (error: any) {
    if (error.message?.includes('[bini-env] Missing required')) {
      return c.json({ error: error.message }, 500)
    }
    return c.json({ error: 'Something went wrong.' }, 500)
  }
})

export default app

3. Your .env file

.env
# Server-side only
DATABASE_URL=postgres://...
STRIPE_SECRET_KEY=sk_live_...

# Exposed to the browser
BINI_API_URL=https://api.example.com
VITE_ANALYTICS_ID=UA-XXXX

4. Dev banner

When the dev or preview server starts, it prints the detected .env files:

>_Terminal
  ß Bini.js (dev)
  ➜  Environments: .env
  ➜  Local:   http://localhost:3000/
  ➜  Network: http://192.168.1.7:3000/

Prefixes

Two prefixes are exposed to the browser: BINI_ and VITE_. Everything else stays server-side.

PrefixExposed to browserUse for
No prefixNeverSecrets - API keys, database URLs, tokens
BINI_YesPublic config
VITE_YesPublic config (Vite default)

Platform Support

Pass the Hono context c to getEnv and requireEnv and they resolve from the correct source on every platform:

PlatformRuntimeEnv source
Node.jsNodeprocess.env
BunBunprocess.env
Vercel EdgeV8 isolateprocess.env
Netlify EdgeDenoDeno.env.get()
Cloudflare WorkersV8 isolatec.env
Deno DeployDenoDeno.env.get()

API Reference

getEnv(source, key)

Returns string | undefined. Use for optional config. An empty value is returned as an empty string, so ?? does not fall back for it.

src/app/api/config.ts
const region = getEnv(c, 'AWS_REGION') ?? 'us-east-1'
const debug  = getEnv(c, 'DEBUG_MODE') === 'true'

requireEnv(source, key)

Returns string. Throws if the variable is missing, empty, or not a string. Use for required config.

>_Terminal
[bini-env] error Missing required environment variable: "SMTP_HOST"
  -> Set it in your hosting dashboard (or in .env for dev, preview and bini-server).

checkEnv(source, keys)

Checks several variables at once. Returns { ok, missing }. Does not throw - logs one error listing every missing name.

src/app/api/setup.ts
const { ok, missing } = checkEnv(c, ['DATABASE_URL', 'REDIS_URL', 'SESSION_SECRET'])
if (!ok) return c.json({ error: `Missing: ${missing.join(', ')}` }, 500)

requireEnvs(source, keys)

Requires several variables at once. Returns a record of key to value. Throws one error listing every missing name.

src/app/api/setup.ts
const { DATABASE_URL, REDIS_URL } = requireEnvs(c, ['DATABASE_URL', 'REDIS_URL'])

biniLogger

Terminal logger with Vite-style timestamps, for your own server-side code.

src/server.ts
import { biniLogger } from 'bini-env'

biniLogger.info('Server ready')
biniLogger.warn('Missing optional var')
biniLogger.error('Something broke', error)

loadEnvFiles(root?, mode?)

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.

src/server.ts
import { loadEnvFiles } from 'bini-env/node'

const { files, injected } = loadEnvFiles(process.cwd(), 'production')

Types

TypeDefinition
HonoContextHono's Context
EnvSourceRecord<string, unknown>
EnvInputHonoContext | EnvSource | undefined | null
EnvCheck{ ok: boolean; missing: string[] }
Was this helpful?
Previousbini-router
Nextbini-native

On this page

  • Overview
  • Requirements
  • Install
  • Quick Start
  • Prefixes
  • Platform Support
  • API Reference
Edit this page on GitHub

bini-env

Official

Environment variable system for Bini.js. Hono-native, works on every runtime.

Overview

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 handlergetEnv(c,key)
dev.envprodplatform env

Requirements

  • hono >= 4.0.0 - required peer dependency
  • Vite >= 8.0.0 - optional peer, only needed for the Vite plugin
  • Node.js >= 20.12.0

Install

>_Terminal
$ npm install bini-env hono

The package has three entry points:

ImportContentsRuns on
bini-envgetEnv, requireEnv, checkEnv, requireEnvs, biniLogger, and typesAny runtime
bini-env/vitebiniEnv()Node, inside Vite
bini-env/nodeloadEnvFiles, envFilesForNode

Quick Start

1. Register the Vite plugin

vite.config.ts
import { defineConfig } from 'vite'
import { biniEnv } from 'bini-env/vite'

export default defineConfig({
  plugins: [biniEnv()],
})

biniEnv() takes no options.

2. Read env vars in a Hono handler

src/app/api/hello.ts
import { Hono } from 'hono'
import { getEnv, requireEnv } from 'bini-env'

const app = new Hono()

app.post('/hello', async (c) => {
  try {
    // requireEnv throws if the var is missing or empty
    const apiKey = requireEnv(c, 'MY_API_KEY')

    // getEnv returns undefined if the var is missing
    const appName = getEnv(c, 'APP_NAME') ?? 'World'

    return c.json({ message: `Hello, ${appName}!` })
  } catch (error: any) {
    if (error.message?.includes('[bini-env] Missing required')) {
      return c.json({ error: error.message }, 500)
    }
    return c.json({ error: 'Something went wrong.' }, 500)
  }
})

export default app

3. Your .env file

.env
# Server-side only
DATABASE_URL=postgres://...
STRIPE_SECRET_KEY=sk_live_...

# Exposed to the browser
BINI_API_URL=https://api.example.com
VITE_ANALYTICS_ID=UA-XXXX

4. Dev banner

When the dev or preview server starts, it prints the detected .env files:

>_Terminal
  ß Bini.js (dev)
  ➜  Environments: .env
  ➜  Local:   http://localhost:3000/
  ➜  Network: http://192.168.1.7:3000/

Prefixes

Two prefixes are exposed to the browser: BINI_ and VITE_. Everything else stays server-side.

PrefixExposed to browserUse for
No prefixNeverSecrets - API keys, database URLs, tokens
BINI_YesPublic config
VITE_YesPublic config (Vite default)

Platform Support

Pass the Hono context c to getEnv and requireEnv and they resolve from the correct source on every platform:

PlatformRuntimeEnv source
Node.jsNodeprocess.env
BunBunprocess.env
Vercel EdgeV8 isolateprocess.env
Netlify EdgeDenoDeno.env.get()
Cloudflare WorkersV8 isolatec.env
Deno DeployDenoDeno.env.get()

API Reference

getEnv(source, key)

Returns string | undefined. Use for optional config. An empty value is returned as an empty string, so ?? does not fall back for it.

src/app/api/config.ts
const region = getEnv(c, 'AWS_REGION') ?? 'us-east-1'
const debug  = getEnv(c, 'DEBUG_MODE') === 'true'

requireEnv(source, key)

Returns string. Throws if the variable is missing, empty, or not a string. Use for required config.

>_Terminal
[bini-env] error Missing required environment variable: "SMTP_HOST"
  -> Set it in your hosting dashboard (or in .env for dev, preview and bini-server).

checkEnv(source, keys)

Checks several variables at once. Returns { ok, missing }. Does not throw - logs one error listing every missing name.

src/app/api/setup.ts
const { ok, missing } = checkEnv(c, ['DATABASE_URL', 'REDIS_URL', 'SESSION_SECRET'])
if (!ok) return c.json({ error: `Missing: ${missing.join(', ')}` }, 500)

requireEnvs(source, keys)

Requires several variables at once. Returns a record of key to value. Throws one error listing every missing name.

src/app/api/setup.ts
const { DATABASE_URL, REDIS_URL } = requireEnvs(c, ['DATABASE_URL', 'REDIS_URL'])

biniLogger

Terminal logger with Vite-style timestamps, for your own server-side code.

src/server.ts
import { biniLogger } from 'bini-env'

biniLogger.info('Server ready')
biniLogger.warn('Missing optional var')
biniLogger.error('Something broke', error)

loadEnvFiles(root?, mode?)

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.

src/server.ts
import { loadEnvFiles } from 'bini-env/node'

const { files, injected } = loadEnvFiles(process.cwd(), 'production')

Types

TypeDefinition
HonoContextHono's Context
EnvSourceRecord<string, unknown>
EnvInputHonoContext | EnvSource | undefined | null
EnvCheck{ ok: boolean; missing: string[] }
Was this helpful?
Previousbini-router
Nextbini-native

On this page

  • Overview
  • Requirements
  • Install
  • Quick Start
  • Prefixes
  • Platform Support
  • API Reference
Edit this page on GitHub