ScriptsApr 11, 2026·3 min read

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.

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.

Frequently Asked Questions

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.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets