Skills2026年4月11日·1 分钟阅读

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 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 29/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Stage only
信任
信任等级:Established
入口
step-1.md
安全暂存命令
npx -y tokrepo@latest install bb30e2f1-3559-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

TL;DR
Elysia delivers end-to-end type safety and near-native performance on the Bun runtime.
§01

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.

§02

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.

§03

How to use

  1. Install Bun and create a new Elysia project.
  2. Define routes with typed schemas.
  3. Run the server.
  4. 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
§04

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.

§05

Related on TokRepo

§06

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.

常见问题

How fast is Elysia compared to Express?+

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.

Does Elysia support WebSockets?+

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.

Can I use Elysia with a database ORM?+

Yes. Elysia works with Prisma, Drizzle, and other TypeScript-compatible ORMs. Use Elysia plugins to integrate database connections and share them across route handlers.

Does Elysia generate OpenAPI documentation?+

Yes. The @elysiajs/swagger plugin automatically generates OpenAPI 3.0 documentation from your route schemas. Access the Swagger UI at /swagger by default.

Is Elysia production-ready?+

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)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产