Elysia — Ergonomic TypeScript Web Framework for Bun
Elysia is a fast, ergonomic TypeScript web framework optimized for Bun runtime. End-to-end type safety, OpenAPI support, and performance that rivals Go and Rust frameworks.
What it is
Elysia is a TypeScript web framework optimized for the Bun runtime. It provides end-to-end type safety from route definition to client consumption, automatic OpenAPI documentation generation, and performance benchmarks that rival Go and Rust frameworks. The framework emphasizes ergonomic API design with minimal boilerplate.
This tool is for TypeScript developers who want fast API development with strong typing. It is especially attractive to teams already using or evaluating Bun as a Node.js alternative.
How it saves time or tokens
Elysia's type inference eliminates the need for separate type definitions, validation schemas, and API documentation. You define a route with its schema once, and Elysia infers types throughout the chain. The framework generates OpenAPI specs automatically, saving the work of maintaining API docs manually.
How to use
- Install Bun and create a new Elysia project.
- Define routes with typed schemas.
- Run the server.
- Access the auto-generated Swagger UI.
# Install Bun
curl -fsSL https://bun.sh/install | bash
# Create project
mkdir my-api && cd my-api
bun init
bun add elysia @elysiajs/swagger
# Run the server
bun run src/index.ts
Example
import { Elysia, t } from 'elysia'
import { swagger } from '@elysiajs/swagger'
const app = new Elysia()
.use(swagger())
.get('/users/:id', ({ params: { id } }) => {
return { id, name: 'Alice', email: 'alice@example.com' }
}, {
params: t.Object({
id: t.String()
}),
response: t.Object({
id: t.String(),
name: t.String(),
email: t.String()
})
})
.post('/users', ({ body }) => {
return { id: crypto.randomUUID(), ...body }
}, {
body: t.Object({
name: t.String(),
email: t.String({ format: 'email' })
})
})
.listen(3000)
console.log('Server running on port 3000')
Types flow from schema to handler to response automatically.
Related on TokRepo
- AI coding tools — More development tools
- Automation tools — API and workflow automation
Common pitfalls
- Elysia requires Bun. It does not run on Node.js or Deno. If your deployment target only supports Node, Elysia is not an option.
- The ecosystem is smaller than Express or Fastify. Some middleware or integrations may not exist yet.
- Bun itself is still maturing. Some Node.js APIs are not fully supported in Bun, which can affect third-party library compatibility.
- End-to-end type safety only works when using Elysia's schema system. Bypassing it with manual types loses the benefit.
- Production deployment patterns for Bun differ from Node.js. PM2 and some hosting platforms may need adjustments.
Frequently Asked Questions
Elysia on Bun is significantly faster than Express on Node.js in benchmarks. The exact multiplier depends on the workload, but typical benchmarks show 5-10x higher throughput for JSON serialization and routing.
Yes. Elysia has built-in WebSocket support with the same type-safe schema system used for HTTP routes. Define message schemas and get full type inference on WebSocket handlers.
Yes. Elysia works with Prisma, Drizzle, and other TypeScript-compatible ORMs. Use Elysia plugins to integrate database connections and share them across route handlers.
Yes. The @elysiajs/swagger plugin automatically generates OpenAPI 3.0 documentation from your route schemas. Access the Swagger UI at /swagger by default.
Elysia is used in production by many teams, though Bun itself is newer than Node.js. Evaluate Bun compatibility with your specific dependencies before deploying to production.
Citations (3)
- Elysia GitHub— Elysia is a TypeScript web framework for Bun
- Elysia Documentation— Elysia documentation and API reference
- Bun Documentation— Bun runtime performance and compatibility
Related on TokRepo
Discussion
Related Assets
doctest — The Fastest Feature-Rich C++ Testing Framework
doctest is a single-header C++ testing framework designed for minimal compile-time overhead and maximum speed.
Chai — BDD/TDD Assertion Library for Node.js
Chai is a flexible assertion library for Node.js and browsers that supports expect, should, and assert styles.
Supertest — HTTP Assertion Library for Node.js APIs
Supertest provides a high-level API for testing HTTP servers in Node.js with fluent assertion chaining.