We use cookies to understand how the site is used and to display ads. Analytics and advertising only run after you accept. You can change your choice anytime. Privacy policy

Skip to content
devvkit
$devvkit learn --librarie hono-guide

Hono Guide

[nodejs][edge][serverless][framework]
JavaScript / TypeScript
Install
npm create hono@latest my-app
npm install hono

Hono means "flame" in Japanese. It's built for edge computing: supporting Cloudflare Workers, Deno, Bun, Vercel Edge, AWS Lambda, and Node.js from the same codebase. No dependencies, zero runtime overhead.

The router (TrieRouter or SmartRouter) is the fastest JS router: matching routes in O(n) with no regex overhead. Middleware ecosystem includes auth, CORS, JWT, compression, GraphQL, and JSX.

Hono's RPC mode gives you tRPC-like type safety. Define a route on the server and call it from the client with full TypeScript inference, no code generation.

Setup

Basic app· Hono server.
import { Hono } from 'hono'

const app = new Hono()

app.get('/', (c) => c.text('Hello Hono!'))

export default app
// npx wrangler dev  # Cloudflare Workers
// deno run --allow-net app.ts  # Deno

Routing

Route params· URL parameters.
app.get('/users/:id', (c) => {
  const id = c.req.param('id')
  return c.json({ id })
})
Query params· Query string.
app.get('/search', (c) => {
  const q = c.req.query('q')
  return c.json({ query: q })
})

Middleware

Middleware· Reusable handlers.
import { cors, logger } from 'hono/middleware'

app.use('*', cors())
app.use('*', logger())

// Custom middleware
app.use('/api/*', async (c, next) => {
  const token = c.req.header('Authorization')
  if (!token) return c.json({ error: 'Unauthorized' }, 401)
  await next()
})
JSX middleware· Server-side rendering.
import { jsxRenderer } from 'hono/jsx-renderer'

app.get('*', jsxRenderer(({ children }) => {
  return <html><body>{children}</body></html>
}))

app.get('/', (c) => c.render(<h1>Hello</h1>))

RPC

Hono RPC· Type-safe client.
// server.ts
import { z } from 'zod'
import { zValidator } from '@hono/zod-validator'

const route = app.get('/users/:id',(c) => c.json({ id: c.req.param('id'), name: 'Alice' }))
export type AppType = typeof route

// client.ts
import { hc } from 'hono/client'
import type { AppType } from './server'
const client = hc<AppType>('http://localhost:3000')
const res = await client.users[':id'].({ param: { id: '1' } })

Deployment

Deploy to Cloudflare· Wrangler deployment.
npx wrangler deploy
# wrangler.toml:
# main = "src/index.ts"
# compatibility_date = "2025-04-01"