Skip to content

Arsybai/hono-dotenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hono-dotenv

🧃 A minimal .env loader + 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. npm version


🚀 Installation

With Bun

bun add hono-dotenv

Or with npm

npm install hono-dotenv

📆 Usage

import { 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}`);
});

Example .env file

APP_NAME=MyCoolApp
PORT=3000

✅ Features

  • 📄 Simple .env file 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

💡 How it works

  • loadDotEnv(path) — parses a .env file into { KEY: VALUE }
  • withEnv(vars) — middleware to inject vars into c.env

You can now access any variable via c.env.KEY in any route handler.


🧪 Example Project

Check the example/ directory for a working Bun app using hono-dotenv.


About

Minimal .env loader and Hono middleware for Bun, Deno, and Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published