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;How it works
Section titled “How it works”new Hono()creates the app;app.get(path, handler)adds a route. The handler gets a contextcand returnsc.text(...),c.json(...)orc.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 afetchmethod, and Bun serves a default export with one on port 3000, so there’s noBun.servecall to write.
Run it locally
Section titled “Run it locally”Install Hono in a new folder and run the file with Bun, which serves the default export:
bun add honobun index.tscurl localhost:3000/api/hello/BunOpen 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.