Skip to main content
Bun is a fast all-in-one JavaScript runtime that includes a bundler, test runner, and package manager. Hono works seamlessly with Bun and takes advantage of its performance.

Quick Start

Create a new Hono project for Bun:
Select “bun” as your template when prompted.

Installation

Add Hono to your existing Bun project:

Basic Usage

Create your application in index.ts:
index.ts
Bun automatically uses the default export as the fetch handler.

Running Your App

Run your Hono app with Bun:
Or use the development mode with hot reload:

Adapter Features

The Bun adapter provides several utilities:

Static Files

Serve static files from a directory:

WebSocket Support

Bun has native WebSocket support. Use Hono’s Bun adapter for WebSockets:

Connection Info

Get connection information including IP address:

Accessing Bun Server

Access the underlying Bun server instance:

Static Site Generation (SSG)

Generate static files from your Hono app:

Custom Server Configuration

Configure the Bun server with custom options:
index.ts

Environment Variables

Bun loads .env files automatically:
.env
Access environment variables:

Using Bun APIs

File System

Use Bun’s fast file system APIs:

SQLite

Use Bun’s built-in SQLite:

Testing

Bun includes a built-in test runner:
index.test.ts
Run tests:

Package Scripts

Set up scripts in package.json:
package.json
Run scripts:

Deployment

Standalone Binary

Build a standalone executable:
Run the binary:

Docker

Create a Dockerfile:
Dockerfile
Build and run:

VPS/Cloud Deployment

1

Install Bun on your server

2

Clone and install dependencies

3

Run with process manager

Use PM2 or systemd:

Best Practices

The --hot flag provides instant feedback during development.
Use Bun.file(), bun:sqlite, and other built-in APIs for better performance.
Bun runs TypeScript natively without a build step.
Bun’s test runner is fast and includes built-in matchers.

Performance Tips

  • Bun is significantly faster than Node.js for I/O operations
  • Use Bun.file() for file operations instead of fs module
  • Leverage Bun’s native WebSocket implementation
  • Use bun:sqlite for embedded databases

Resources

Bun Documentation

Official Bun documentation

Bun Runtime APIs

Explore Bun’s built-in APIs