Contents
Hono
A small, fast web framework on web standards: runs on Node.js, Bun, Deno and Cloudflare Workers.
1.Getting started
- What Hono isWhy Hono exists, what the Request and Response web standards are, and which platforms it runs on.
- Creating a projectHow to create a Hono project with npm create hono and what lives in its folders.
- The first appWhat src/index.ts is made of, how Hono runs on Node.js and how to return your first JSON.
2.Routes and requests
- Routes and HTTP methodsHow to map an address and an HTTP method to a handler: app.get, app.post, app.put, app.delete and app.on.
- Path parameters and queryHow to read part of the address with c.req.param() and the parameters after the question mark with c.req.query().
- The Context objectWhat the c object holds: request data in c.req and the response methods c.json, c.text, c.html, c.redirect, c.status and c.header.
- The request bodyHow to read JSON, form data and text from the request body: c.req.json(), c.req.parseBody() and c.req.formData().
- Route groups and separate filesHow to move the post routes into their own file and mount them with app.route() and basePath().
3.Middleware and validation
- MiddlewareWhat middleware is in Hono, how await next() works and how to write your own middleware with createMiddleware.
- Built-in middlewareHono's ready-made middleware: logger, cors, secureHeaders, etag and basicAuth — what each does and how to attach it.
- Validation with zodHow to check the request body, parameters and query against a zod schema with the zValidator middleware and get data with ready-made types.
- Error handlingHow to answer unknown addresses with app.notFound(), catch errors with app.onError() and stop a request with an HTTPException.
- Environment variables and bindingsWhere to keep secrets and settings, how to load a .env file in Node.js and how to read variables with env() and c.env.
4.Pages and data
- HTML with JSXHow to build HTML pages with Hono's built-in JSX: .tsx files, components, props and lists.
- A shared page layoutHow to move shared markup into a Layout component with children and apply it to every page with jsxRenderer and c.render().
- An SQLite databaseHow to connect SQLite to a Hono app on Node.js with better-sqlite3: the database file, tables and queries.
- A CRUD API for postsThe full set of routes for blog posts: list, view, create, update and delete with zod validation and an SQLite database.
5.Users
6.Going further
- The hc RPC clientHow to export the app type and call the API from TypeScript code with the hc client, with hints for addresses, parameters and responses.
- Tests with app.request()How to test Hono routes without starting a server: app.request(), Vitest and a separate database for tests.
- Deployment: Node.js, Bun, Deno, Cloudflare WorkersHow to run a Hono app in production on Node.js and how starting it on Bun, Deno and Cloudflare Workers differs.