Skip to content

Hono Tutorial

Official Documentation

This tutorial is based on the official Hono documentation. For the most up-to-date information, visit: https://hono.dev

Welcome to the comprehensive Hono tutorial! Learn how to build fast, lightweight web applications with Hono - the ultrafast web framework for the Edge.

What is Hono?

Hono (炎 means "flame" in Japanese) is a small, simple, and ultrafast web framework for the Edge. It works on any JavaScript runtime: Cloudflare Workers, Deno, Bun, Vercel, AWS Lambda, Node.js, and more.

typescript
// A simple Hono application
import { Hono } from 'hono'

const app = new Hono()

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

export default app

Why Hono?

Key Features

FeatureDescription
UltrafastOne of the fastest routers in the JavaScript ecosystem
LightweightZero dependencies, small bundle size (~14KB)
Multi-runtimeWorks on Cloudflare Workers, Deno, Bun, Node.js, and more
TypeScriptFirst-class TypeScript support with type inference
MiddlewareRich middleware ecosystem for common tasks
Web StandardsBuilt on Web Standard APIs (Request/Response)

Performance Comparison

Hono is designed for speed. Here's how it compares:

Hono        ████████████████████████████████ 100%
Express     ███████████████                   47%
Fastify     ██████████████████████████        81%

Runtime Support

Hono runs everywhere:

  • Cloudflare Workers - Edge computing
  • Deno - Secure runtime
  • Bun - Fast all-in-one toolkit
  • Node.js - Traditional server
  • AWS Lambda - Serverless
  • Vercel - Edge Functions
  • Netlify - Edge Functions

Tutorial Structure

Beginner

  1. Getting Started - Installation, first app, basic concepts
  2. Routing - Routes, parameters, groups, methods

Intermediate

  1. Middleware - Built-in and custom middleware
  2. Context API - Request, response, and context helpers
  3. Validation - Input validation with Zod

Advanced

  1. Testing - Unit and integration testing
  2. Deployment - Deploy to various platforms
  3. Advanced Topics - RPC, streaming, WebSockets, best practices

Quick Example

Here's a taste of what you'll learn:

typescript
import { Hono } from 'hono'
import { cors } from 'hono/cors'
import { logger } from 'hono/logger'
import { validator } from 'hono/validator'

const app = new Hono()

// Middleware
app.use('*', logger())
app.use('/api/*', cors())

// Routes
app.get('/', (c) => {
    return c.html('<h1>Welcome to Hono!</h1>')
})

// Route with parameters
app.get('/users/:id', (c) => {
    const id = c.req.param('id')
    return c.json({ id, name: 'John Doe' })
})

// POST with validation
app.post('/users',
    validator('json', (value, c) => {
        const { name, email } = value
        if (!name || !email) {
            return c.json({ error: 'Invalid input' }, 400)
        }
        return { name, email }
    }),
    (c) => {
        const data = c.req.valid('json')
        return c.json({ message: 'User created', data }, 201)
    }
)

// Error handling
app.onError((err, c) => {
    console.error(err)
    return c.json({ error: 'Internal Server Error' }, 500)
})

// 404 handling
app.notFound((c) => {
    return c.json({ error: 'Not Found' }, 404)
})

export default app

Prerequisites

Before starting this tutorial, you should have:

  • Basic knowledge of JavaScript/TypeScript
  • Node.js 18+ (or Bun/Deno)
  • A code editor (VS Code recommended)
  • Basic understanding of HTTP and REST APIs

What You'll Build

Throughout this tutorial, you'll build:

  1. REST API - A complete CRUD API
  2. Authentication System - JWT-based auth
  3. Validated Endpoints - Input validation with Zod
  4. Edge-ready App - Deploy to Cloudflare Workers

Video Tutorials

Recommended Video Resources

Learn Hono through these excellent video tutorials from the community.

Free Courses

CourseCreatorDescription
Hono.js Crash CourseTraversy Media45-minute crash course
Hono TutorialBeyond FireshipBuild APIs with Hono
Hono + Cloudflare WorkersJames Q QuickDeploy to the Edge

Official Resources

ResourceDescription
Hono DocumentationOfficial Hono documentation
Hono ExamplesOfficial code examples

Topic-Specific Videos

TopicVideoDuration
Cloudflare WorkersHono on Workers~20 min
AuthenticationJWT with Hono~25 min
Zod ValidationHono + Zod~15 min

Let's begin your Hono journey!


Start with Introduction →