Hono is a small web framework built on Web Standards that runs on Workers, Bun, Deno and Node.js. Setup, routing, middleware, validation, RPC and pitfalls.
Hono is a small, zero-dependency web framework built on Web Standards (Request, Response, fetch) that runs the same application code on Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Netlify, AWS Lambda, Lambda@Edge and Node.js.[1] The verdict: pick Hono when you want an Express-style API on an edge or multi-runtime target, with first-class TypeScript and built-in middleware. Skip it if you need a full-stack framework with an ORM and an admin panel, because Hono describes itself as a web application framework "without a frontend".[1] Below: setup, routing, the Context object, middleware, the five routers, validation, typed RPC, per-runtime entry points and a table of mistakes that bite people in practice.
What Hono is
The name means "flame" in Japanese.[1] The docs list five headline features: an ultrafast router (RegExpRouter), a lightweight core (the hono/tiny preset is under 14kB, with zero dependencies), multi-runtime support, built-in and third-party middleware, and TypeScript-first APIs.[1] The MIT-licensed project lives at github.com/honojs/hono; the repository page showed 33.2k stars and release v4.13.23 dated November 26, 2026 when checked for this article.[12]
Because it is built on Web Standards, the application code stays the same everywhere. Only the entry point changes.[2]
| Runtime | Entry point | Extra package |
|---|---|---|
| Cloudflare Workers | export default app | None. Wrangler runs and deploys it[10] |
| Bun | export default app, or an object with port and fetch | None. @hono/bun only for static files[11] |
| Node.js | serve(app) from @hono/node-server | @hono/node-server[9] |
| Deno, Fastly, Vercel, Netlify, AWS Lambda, Lambda@Edge | Listed as supported; each has its own guide | See the platform guide[1] |
On Node.js, the docs say Hono was not designed for it at first but works through the adapter on versions above 18.x: 18.14.1+, 19.7.0+ and 20.0.0+.[9]
Set up a Hono project
The starter command is create-hono. It asks which template you want. The list in the docs includes aws-lambda, bun, cloudflare-pages, cloudflare-workers, deno, fastly, nextjs, nodejs and vercel.[2]
npm create hono@latest my-app
cd my-app
npm i
npm run devThe same page gives equivalents for yarn, pnpm, bun and deno. For an existing Bun project, bun add hono is enough, plus a dev script of bun run --hot src/index.ts.[11] The dev server answers on port 8787 for Workers and port 3000 for Node.js and Bun.[2][9][11]
Routing and the Context object
Every handler receives a Context (conventionally c) that exists for one request. It exposes the request through c.req, sets the status and headers, and builds the response.[4]
import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) => c.text('Hello Hono!'))
app.get('/posts/:id', (c) => {
const page = c.req.query('page')
const id = c.req.param('id')
c.header('X-Message', 'Hi!')
return c.text('You want to see ' + page + ' of ' + id)
})
app.post('/posts', (c) => c.text('Created!', 201))
app.get('/api/hello', (c) => c.json({ ok: true, message: 'Hello Hono!' }))
const book = new Hono()
book.get('/', (c) => c.text('List Books'))
book.get('/:id', (c) => c.text('Get Book: ' + c.req.param('id')))
app.route('/book', book)
export default appThose calls come straight from the Getting Started and Routing pages.[2][3] The response helpers are c.text(), c.json(), c.html(), c.body(), c.redirect() (default status 302) and c.notFound(). You can also return a raw new Response(...).[2][4]
Route pattern reference
| Pattern | Example | What it does |
|---|---|---|
| Path parameter | /user/:name | Read with c.req.param('name'), or all at once with c.req.param()[3] |
| Optional parameter | /api/animal/:type? | Matches /api/animal and /api/animal/:type[3] |
| Regexp | /post/:date{[0-9]+}/:title{[a-z]+} | Constrains each parameter[3] |
| Wildcard | /wild/*/card | Wildcard in the middle of a path[3] |
| Any method | app.all('/hello', ...) | Handles every HTTP method[3] |
| Custom method | app.on('PURGE', '/cache', ...) | Handles a non-standard method[3] |
| Base path | new Hono().basePath('/api') | /book becomes /api/book[3] |
One rule decides most routing bugs: handlers and middleware run in registration order, and once a handler returns, processing stops.[3] Register app.get('/book/a', ...) before app.get('/book/:slug', ...). Put a catch-all * last if it is a fallback. Put it first and nothing below it ever runs.
Middleware
The docs call the primitive that returns a Response a "Handler". Middleware runs before and after the handler, like an onion.[5] Everything before await next() runs on the way in; everything after runs on the way out, once the handler has produced a response.
import { Hono } from 'hono'
import { etag } from 'hono/etag'
import { logger } from 'hono/logger'
import { basicAuth } from 'hono/basic-auth'
const app = new Hono()
app.use(etag(), logger())
app.use(async (c, next) => {
const start = performance.now()
await next()
const end = performance.now()
c.res.headers.set('X-Response-Time', String(end - start))
})
app.use(
'/admin/*',
basicAuth({
username: 'admin',
password: 'secret',
})
)
app.get('/admin', (c) => c.text('You are authorized!'))The timing middleware is the docs' own example; etag() plus logger() and the basicAuth block also come from the docs.[1][2][5] Hardcoded credentials are for the demo only. Read them from your environment. On Workers that means c.env inside a wrapper, covered below. For what each status code means when auth fails, see the 401 vs 403 explainer.
Built-in middleware and helpers
The docs home page lists these as shipping with Hono.[1]
| Need | Import path or name |
|---|---|
| Basic and Bearer auth | hono/basic-auth, Bearer Authentication |
| JWT auth | JWT Authentication middleware |
| CORS, ETag, compression | CORS, hono/etag, Compress |
| Caching and body size | Cache, Body Limit |
| Logging and headers | hono/logger, Secure Headers, Pretty JSON |
| Cookies, HTML, JSX, streaming, SSG | Cookie, html, JSX, Streaming, SSG helpers |
| Context Storage, Language | Context Storage, Language |
The built-in list has no rate limiter, so you add one or return a 429 yourself. The HTTP 429 guide covers what a good one sends back.
To pass values from middleware to handlers, use c.set('key', value) and c.get('key'). They live only for the current request. Declare a Variables type on the Hono generic to type them.[4]
The five routers
Routing speed is a headline feature, and the router is swappable. The docs describe five.[6]
| Router | Idea | Trade-off |
|---|---|---|
| RegExpRouter | Compiles all routes into one large regular expression before dispatch | Fastest, but does not support every pattern[6] |
| TrieRouter | Trie-tree matching | Slower than RegExpRouter, supports all patterns[6] |
| SmartRouter | Picks the best router from the registered routes at startup | The default wraps RegExpRouter and TrieRouter[6] |
| LinearRouter | Adds routes without compiling strings | Fast registration, for environments that initialize on every request[6] |
| PatternRouter | Adds and matches patterns directly | Smallest: an app using only it is under 15KB[6] |
Most apps never touch this. The default SmartRouter handles it. The docs also publish a project-reported Cloudflare Workers router benchmark where Hono scored 402,820 ops/sec against 212,598 for itty-router, 297,036 for sunder and 197,345 for worktop.[1] That is the project's own measurement of routers only, not an end-to-end throughput test, so treat it as a pointer rather than a promise. Your database and network will dominate real latency.
On size, the project-reported figures are that hono/tiny is under 14KB minified, against 572KB for Express. The GitHub README says under 12kB for the same preset, so the two project pages disagree slightly.[1][12] Either way it is a small core. Middleware and adapters are bundled only when you import them.[1]
Validation and typed RPC
Hono ships only a thin validator and recommends a third-party library. The validator function from hono/validator works as middleware, with targets json, form, query, header, param and cookie.[7] The Zod middleware and the Standard Schema middleware are separate packages.
// server.ts
import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator'
import * as z from 'zod'
const app = new Hono()
const route = app.post(
'/posts',
zValidator(
'form',
z.object({
title: z.string(),
body: z.string(),
})
),
(c) => {
return c.json({ ok: true, message: 'Created!' }, 201)
}
)
export type AppType = typeof route
// client.ts
import { hc } from 'hono/client'
import type { AppType } from './server'
const client = hc<AppType>('http://localhost:8787/')
const res = await client.posts.$post({
form: {
title: 'Hello',
body: 'Hono is a cool project',
},
})
if (res.ok) {
const data = await res.json()
console.log(data.message)
}That is the RPC feature: export typeof your app (or route), pass it to hc as a generic, and the client infers both the validated input and the c.json() output.[8] Specify status codes in c.json() (for example 404) and the client can narrow on res.status. Install with npm i @hono/zod-validator zod.[7][8] For monorepos, the docs ask for "strict": true in both the client and server tsconfig files.[8]
Runtime specifics: bindings and Node.js
On Cloudflare Workers, environment variables, KV namespaces, R2 buckets and Durable Objects arrive as bindings on c.env. Pass a type to the Hono generic to get typed access.[10] On Node.js you wrap the app with the adapter.[9]
// Cloudflare Workers
import { Hono } from 'hono'
import { basicAuth } from 'hono/basic-auth'
type Bindings = {
USERNAME: string
PASSWORD: string
}
const app = new Hono<{ Bindings: Bindings }>()
app.use('/auth/*', async (c, next) => {
const auth = basicAuth({
username: c.env.USERNAME,
password: c.env.PASSWORD,
})
return auth(c, next)
})
export default app
// Node.js (separate file; import your app from the module above)
import { serve } from '@hono/node-server'
serve({
fetch: app.fetch,
port: 8787,
})The wrapper that builds basicAuth inside the handler is the documented pattern for using secrets in middleware on Workers.[10] To combine Hono with other Workers event handlers such as scheduled, export an object with fetch: app.fetch plus the extra handler.[10]
What breaks: common mistakes
| Mistake | What happens | Fix |
|---|---|---|
Catch-all app.get('*', ...) registered before specific routes | Specific routes are never dispatched[3] | Register specific routes first, fallback last |
| Middleware registered below the handler | It does not run for that route[3] | Write app.use() above the handlers it should wrap |
Calling app.route('/two', two) before two has its routes | 404, because route() copies the routes stored at that moment[3] | Mount the innermost group first |
Validating json or form without a matching Content-Type | The callback receives {}[7] | Send the header, including in app.request() tests |
Header validator keyed Idempotency-Key | Value is always undefined[7] | Use the lowercase key idempotency-key |
Reading process.env on Workers | Not available by default[10] | Use c.env, or enable the nodejs_compat_populate_process_env flag |
Returning c.notFound() in an RPC route | Client data is unknown[8] | Return c.json({ error: 'not found' }, 404) |
Handler returns a .then() chain | Client infers unknown[8] | Use async/await |
serveStatic root on Node.js | Resolves from process.cwd(), so it breaks if you start the process elsewhere[9] | Build the path from import.meta.url |
Protecting static files with app.use('/admin/*', auth) | Route matching is case-sensitive but Windows and macOS file systems may not be, so /ADMIN/secret.txt can skip the middleware[9][11] | Keep protected files outside the served directory |
Two more from the Context docs. ContextVariableMap adds types globally, so c.get('result') looks typed even in routes where the middleware never ran, which hides undefined bugs.[4] And on a large RPC app, type inference gets expensive: the docs warn that IDE speed drops as routes grow and suggest compiling the client type ahead of time or splitting the app into several clients.[8]
When Hono fits, and when it does not
Hono fits web APIs, backend proxies, CDN-edge logic and base servers for libraries. The docs name those use-cases and list cdnjs, Cloudflare D1 and Workers KV internals, Unkey, OpenStatus and Clerk as production users.[1] It fits teams that already write TypeScript and want request and response types to follow them from the route to the client.
It fits less well when you want conventions handed to you. There is no bundled ORM, user-account system or admin UI, only middleware and helpers (the docs do list full-stack applications as a use-case, but you assemble that stack yourself). Adapters for platform features such as WebSocket or static files ship as separate packages, and their names differ per runtime, so a "same code everywhere" app still has a few runtime-specific lines.[2][9][11] That is the honest cost of portability: the routing and handler code moves, the edges do not.
Sources
- Hono, Web framework built on Web Standards, hono.dev docs home (accessed December 1, 2026)
- Getting Started, Hono docs (accessed December 1, 2026)
- Routing, Hono docs (accessed December 1, 2026)
- Context, Hono docs (accessed December 1, 2026)
- Middleware, Hono docs (accessed December 1, 2026)
- Routers, Hono docs (accessed December 1, 2026)
- Validation, Hono docs (accessed December 1, 2026)
- RPC, Hono docs (accessed December 1, 2026)
- Node.js, Hono docs (accessed December 1, 2026)
- Cloudflare Workers, Hono docs (accessed December 1, 2026)
- Bun, Hono docs (accessed December 1, 2026)
- honojs/hono, README, license and releases, GitHub (accessed December 1, 2026)
Written by
WOWHOW
The WOWHOW team brings 14+ years of production engineering experience. Every tool and product in the catalog is built, tested, and curated in-house.
Monday memo · free
One insight, every Monday. 7am IST.
1 field report, 3 links, 1 tool we actually use. No fluff, no spam.
Beyond the writing
Need production-ready templates?
Free browser tools with no signup, plus premium dev templates and starter kits.
Comments · 0
Beta: comments are stored locally on your device and not visible to other readers.
No comments yet. Be the first to share your thoughts.