Quick Start
Create a new Hono project for Bun:Installation
Add Hono to your existing Bun project:Basic Usage
Create your application inindex.ts:
index.ts
Bun automatically uses the
default export as the fetch handler.Running Your App
Run your Hono app with Bun: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
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
Package Scripts
Set up scripts inpackage.json:
package.json
Deployment
Standalone Binary
Build a standalone executable:Docker
Create aDockerfile:
Dockerfile
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
Use hot reload in development
Use hot reload in development
The
--hot flag provides instant feedback during development.Leverage Bun's built-in APIs
Leverage Bun's built-in APIs
Use
Bun.file(), bun:sqlite, and other built-in APIs for better performance.Enable TypeScript
Enable TypeScript
Bun runs TypeScript natively without a build step.
Use bun test
Use bun test
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 offsmodule - Leverage Bun’s native WebSocket implementation
- Use
bun:sqlitefor embedded databases
Resources
Bun Documentation
Official Bun documentation
Bun Runtime APIs
Explore Bun’s built-in APIs