Skip to content
Run BunYour friendly Bun playground

Hono on Bun example: a Hono app in your browser

Hono is a small web framework that runs on Bun, Deno, Node and edge runtimes. On Bun, a module that exports an object with a fetch method is served automatically. Press Run to install Hono and start the app.

import { Hono } from "hono";
import { logger } from "hono/logger";

const app = new Hono();

app.use(logger());
app.get("/", (c) => c.text("Hello Hono!"));
app.get("/api/hello/:name", (c) => c.json({ message: `Hello, ${c.req.param("name")}!` }));
app.get("/api/time", (c) => c.json({ now: new Date().toISOString(), bun: Bun.version }));

export default app;
  • new Hono() creates the app; app.get(path, handler) adds a route. The handler gets a context c and returns c.text(...), c.json(...) or c.html(...).
  • c.req.param("name") reads a path parameter.
  • app.use(logger()) adds middleware to every route: here it logs each request to the console.
  • export default app: Hono’s app has a fetch method, and Bun serves a default export with one on port 3000, so there’s no Bun.serve call to write.

Install Hono in a new folder and run the file with Bun, which serves the default export:

Terminal window
bun add hono
bun index.ts
curl localhost:3000/api/hello/Bun

Open the official Hono Bun starter straight from GitHub in the playground. Frameworks lists what else runs.

Was this page helpful?

Sends the rating and this page's address; nothing else unless you write it. Privacy

runbun is an independent project, not affiliated with or endorsed by Oven or Bun.