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.
这个资产会安全暂存
这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。
npx -y tokrepo@latest install bb30e2f1-3559-11f1-9bc6-00163e2b0d79 --target codex先暂存文件;激活前需要读取暂存 README 和安装计划。
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.
常见问题
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.
引用来源 (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
讨论
相关资产
Axum — Ergonomic Modular Web Framework for Rust
Axum is a web application framework built on Tokio, Tower, and Hyper. Focuses on ergonomics and modularity with a macro-free routing API, seamless Tower middleware integration, and type-safe extractors. The official Tokio team web framework.
Better Auth — Framework-Agnostic Authentication for TypeScript
Better Auth is a comprehensive TypeScript authentication library that provides email/password, OAuth, multi-factor, and session management out of the box. It works with any framework and any database, offering a plugin system for extending authentication flows without vendor lock-in.
vanilla-extract — Zero-Runtime Type-Safe CSS in TypeScript
A CSS-in-TypeScript framework that generates static CSS files at build time, giving you type-safe style authoring with zero runtime cost and standard CSS output.
TypeScript — JavaScript with Syntax for Types
TypeScript is a superset of JavaScript that adds static types, interfaces, generics, and modern ES features, compiled down to plain JavaScript. Created by Anders Hejlsberg at Microsoft. Used by Airbnb, Slack, Asana, and a huge share of modern web projects.