🧃 A minimal
.envloader + middleware for the Hono web framework — fully compatible with Bun, Deno, and Node.js.
This package lets you easily load environment variables from a .env file and inject them into the Hono Context as c.env.
bun add hono-dotenvnpm install hono-dotenvimport { Hono } from 'hono';
import { loadDotEnv, withEnv } from 'hono-dotenv';
const app = new Hono();
// Load env from .env file
const envVars = loadDotEnv();
// Inject to all routes
app.use('*', withEnv(envVars));
app.get('/', (c) => {
return c.text(`Hello from ${c.env.APP_NAME}, port ${c.env.PORT}`);
});APP_NAME=MyCoolApp
PORT=3000
- 📄 Simple
.envfile parser - ⚡ Fast, zero-dependency, works with Bun
- 🔒 Safe injection via middleware
- 🧠 Fully typed for TypeScript (with IntelliSense)
- 🔀 Works in all environments: Bun, Deno, Node.js
loadDotEnv(path)— parses a.envfile into{ KEY: VALUE }withEnv(vars)— middleware to inject vars intoc.env
You can now access any variable via c.env.KEY in any route handler.
Check the example/ directory for a working Bun app using hono-dotenv.