Skip to Content

Last Updated: 3/11/2026


Bun

Bun  is a fast JavaScript runtime with built-in TypeScript support. Hono works seamlessly on Bun.

Install Bun

Follow the instructions at bun.com  to install the bun command.

Setup

Create a new Bun project:

bun create hono@latest my-app

Select bun when prompted, then install dependencies:

cd my-app bun install

Existing Project

To add Hono to an existing Bun project:

bun add hono

Add the dev script to package.json:

{ "scripts": { "dev": "bun run --hot src/index.ts" } }

Hello World

Create src/index.ts:

import { Hono } from 'hono' const app = new Hono() app.get('/', (c) => c.text('Hello Bun!')) export default app

Run Locally

Start the development server:

bun run dev

Access http://localhost:3000 in your browser.

Change Port

Export a port property:

import { Hono } from 'hono' const app = new Hono() app.get('/', (c) => c.text('Hello Bun!')) export default { port: 8787, fetch: app.fetch, }

Serve Static Files

Use serveStatic from hono/bun:

import { serveStatic } from 'hono/bun' const app = new Hono() app.use('/static/*', serveStatic({ root: './' })) app.use('/favicon.ico', serveStatic({ path: './favicon.ico' })) app.get('/', (c) => c.text('You can access: /static/hello.txt'))

Directory structure:

./ ├── favicon.ico ├── src └── static ├── hello.txt └── images └── logo.png

Options

rewriteRequestPath: Map URLs to different paths:

app.get( '/static/*', serveStatic({ root: './', rewriteRequestPath: (path) => path.replace(/^\/static/, '/statics'), }) )

mimes: Add custom MIME types:

app.get( '/static/*', serveStatic({ mimes: { m3u8: 'application/vnd.apple.mpegurl', ts: 'video/mp2t', }, }) )

precompressed: Serve pre-compressed files:

app.get( '/static/*', serveStatic({ precompressed: true, }) )

Testing

Use bun:test for testing:

import { describe, expect, it } from 'bun:test' import app from '.' describe('My first test', () => { it('Should return 200 Response', async () => { const req = new Request('http://localhost/') const res = await app.fetch(req) expect(res.status).toBe(200) }) })

Run tests:

bun test index.test.ts