Bun.js Frameworks
Bun's native HTTP server can handle up to 500,000+ requests per second, making it an ideal runtime for high-performance web frameworks. Here's a comprehensive guide to the best frameworks optimized for Bun.
Hono
Hono is an ultrafast, lightweight web framework designed for edge computing. It works seamlessly across Cloudflare Workers, Deno, and Bun with zero dependencies.
Key Features:
- ~14KB bundle size (minified)
- Built-in middleware: CORS, JWT, Basic Auth, ETag, Logger
- TypeScript-first with excellent type inference
- Multi-runtime support (Bun, Deno, Cloudflare Workers, Node.js)
Quick Start:
import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) => c.text('Hello Bun!'))
app.get('/api/users/:id', (c) => {
const id = c.req.param('id')
return c.json({ id, name: 'John' })
})
export default app
Performance: ~150,000 req/s on Bun (varies by hardware)
ElysiaJS
ElysiaJS is built from the ground up for Bun, offering end-to-end type safety and exceptional performance. It's currently one of the fastest Bun frameworks available.
Key Features:
- End-to-end type safety with TypeScript
- Built-in validation using TypeBox
- OpenAPI/Swagger documentation generation
- WebSocket support out of the box
- Plugin ecosystem (JWT, CORS, GraphQL, tRPC)
Quick Start:
import { Elysia, t } from 'elysia'
const app = new Elysia()
.get('/', () => 'Hello Elysia')
.post('/users', ({ body }) => {
return { id: 1, ...body }
}, {
body: t.Object({
name: t.String(),
email: t.String({ format: 'email' })
})
})
.listen(3000)
console.log(`Server running at http://localhost:${app.server?.port}`)
Performance: ~200,000+ req/s on Bun
Bao.js
Bao.js is a minimalist web framework inspired by Express, designed specifically for Bun. It offers a familiar API for developers coming from the Node.js ecosystem.
Key Features:
- Express-like routing syntax
- Middleware support
- Built-in body parsing
- Lightweight and simple
Quick Start:
import Bao from 'baojs'
const app = new Bao()
app.get('/', (ctx) => {
return ctx.sendText('Hello from Bao.js!')
})
app.post('/api/data', async (ctx) => {
const body = await ctx.req.json()
return ctx.sendJson({ received: body })
})
app.listen({ port: 3000 })
Shumai
Shumai is a differentiable tensor library for TypeScript, built by Meta Research. It enables machine learning workflows directly in Bun with GPU acceleration.
Key Features:
- Automatic differentiation for ML training
- GPU acceleration via Flashlight
- Network-connected for distributed computing
- NumPy-like tensor operations
Quick Start:
import * as sm from '@shumai/shumai'
// Create tensors
const a = sm.randn([128, 64])
const b = sm.randn([64, 32])
// Matrix multiplication
const c = a.matmul(b)
// Automatic differentiation
const x = sm.randn([10]).requireGrad()
const y = x.mul(x).sum()
y.backward()
console.log(x.grad) // dy/dx = 2x
GraphQL Yoga
GraphQL Yoga is a fully-featured GraphQL server that runs natively on Bun with excellent performance.
Key Features:
- Subscriptions via Server-Sent Events
- File uploads support
- Apollo Federation compatible
- Built-in GraphiQL IDE
- Automatic persisted queries
Quick Start:
import { createSchema, createYoga } from 'graphql-yoga'
const yoga = createYoga({
schema: createSchema({
typeDefs: `
type Query {
hello(name: String): String!
users: [User!]!
}
type User {
id: ID!
name: String!
}
`,
resolvers: {
Query: {
hello: (_, { name }) => `Hello ${name || 'World'}!`,
users: () => [
{ id: '1', name: 'Alice' },
{ id: '2', name: 'Bob' }
]
}
}
})
})
Bun.serve({
fetch: yoga,
port: 4000
})
StricJS
StricJS focuses on raw performance with a minimal API surface. It's designed for developers who need maximum throughput.
Key Features:
- Radix tree-based routing
- Minimal overhead
- Static file serving
- WebSocket support
Quick Start:
import { Router } from '@stricjs/router'
const app = new Router()
.get('/', () => new Response('Hello StricJS!'))
.get('/users/:id', (ctx) => {
return Response.json({ id: ctx.params.id })
})
export default app
Buchta
Buchta is a full-stack framework with built-in support for modern frontend frameworks like Svelte and Preact.
Key Features:
- SSR support for Svelte, Preact
- Markdown rendering
- File-based routing
- Hot module replacement
Quick Start:
import { Buchta } from 'buchta'
const app = new Buchta()
// File-based routing from ./pages directory
app.pages('./pages')
// API routes
app.get('/api/health', () => ({ status: 'ok' }))
app.listen(3000)
Framework Comparison
| Framework | Best For | Bundle Size | Type Safety |
|---|---|---|---|
| Hono | Edge/Multi-runtime | ~14KB | Good |
| ElysiaJS | Full-featured APIs | ~20KB | Excellent |
| Bao.js | Express migration | ~5KB | Basic |
| StricJS | Raw performance | ~3KB | Basic |
| Buchta | Full-stack apps | ~50KB | Good |
| GraphQL Yoga | GraphQL APIs | ~100KB | Excellent |
Getting Started
Install any framework with Bun:
# Create a new project
bun init
# Install your preferred framework
bun add hono
# or
bun add elysia
# or
bun add baojs
# Run your server
bun run index.ts
All these frameworks leverage Bun's native HTTP server (Bun.serve()) for optimal performance.