{ ILoveJS }

Elysia

Backend Frameworks

Ergonomic framework for Bun

weekly downloads310K
versionv1.4.25
licenseMIT
Bun-native speedEnd-to-end type safetyEden treaty client

Overview

Elysia is a modern HTTP framework built specifically for Bun runtime that prioritizes type safety, developer experience, and performance. It provides end-to-end TypeScript type inference that goes beyond typical frameworks by automatically deriving types from validation schemas, ensuring compile-time correctness for request handlers, responses, and error cases without manual type annotations.

The framework distinguishes itself through its automatic OpenAPI/Swagger documentation generation, which derives complete API specifications directly from TypeScript code without requiring decorators or manual configuration. This approach ensures documentation stays synchronized with implementation, reducing maintenance overhead common in API development. Elysia uses TypeBox for runtime validation while maintaining full type safety, though it also supports popular schema libraries like Zod and Valibot.

With over 309,000 weekly downloads and active development (last published 2 days ago), Elysia has gained traction among developers building high-performance APIs on Bun. Its plugin system enables modular architecture, while support for multiple runtimes (Bun, Node.js, Deno, Cloudflare Workers) provides deployment flexibility. The framework offers a chainable API design that reduces boilerplate while maintaining readability, making it particularly appealing for teams transitioning from Express or looking for lighter alternatives to NestJS.

Elysia targets developers who want the type safety of frameworks like tRPC but with REST API conventions, or those seeking better performance than traditional Node.js frameworks without sacrificing developer experience. The framework handles standard HTTP operations, WebSockets, file uploads, streaming, and lifecycle hooks through a consistent, well-documented API.

Quick Start

typescript
import { Elysia, t } from 'elysia';

const app = new Elysia()
  .get('/', () => 'Hello Elysia')
  .get('/users/:id', ({ params }) => ({
    id: params.id,
    name: 'John Doe',
    email: 'john@example.com'
  }), {
    params: t.Object({
      id: t.String()
    }),
    response: t.Object({
      id: t.String(),
      name: t.String(),
      email: t.String()
    })
  })
  .post('/users', async ({ body }) => {
    return {
      success: true,
      user: {
        id: crypto.randomUUID(),
        ...body
      }
    };
  }, {
    body: t.Object({
      name: t.String({ minLength: 1 }),
      email: t.String({ format: 'email' }),
      age: t.Optional(t.Number({ minimum: 0 }))
    }),
    response: t.Object({
      success: t.Boolean(),
      user: t.Object({
        id: t.String(),
        name: t.String(),
        email: t.String(),
        age: t.Optional(t.Number())
      })
    })
  })
  .onError(({ code, error }) => {
    if (code === 'VALIDATION') {
      return { error: 'Invalid request data', details: error.message };
    }
    return { error: 'Internal server error' };
  })
  .listen(3000);

console.log(`Server running at http://localhost:${app.server?.port}`);

Use Cases

Building Type-Safe REST APIs: Elysia excels at creating REST APIs where type safety is critical. The framework automatically infers request and response types from validation schemas, eliminating the manual synchronization between runtime validators and TypeScript types that plagues many Express or Fastify applications.

Microservices Architecture: The plugin system and lightweight nature make Elysia suitable for microservices where each service needs consistent validation, error handling, and documentation. The automatic OpenAPI generation simplifies service discovery and client generation across service boundaries.

Real-Time Applications: With native WebSocket support integrated into the same routing system as HTTP endpoints, Elysia works well for applications mixing traditional REST with real-time features like chat systems, live dashboards, or collaborative tools.

Serverless/Edge Functions: Elysia's Web Standards compatibility and small footprint make it appropriate for Cloudflare Workers or other edge environments where cold start time and bundle size matter, while still maintaining full framework capabilities.

Internal Tools and Admin Panels: The automatic Swagger UI generation provides instant API explorers without additional tooling, making Elysia practical for internal tools where developer productivity and self-documenting APIs reduce coordination overhead between frontend and backend teams.

Pros & Cons

Pros

  • +True end-to-end type safety with automatic inference from schemas, eliminating manual type definitions and reducing type/runtime validation mismatches
  • +Automatic OpenAPI/Swagger generation without decorators or configuration, keeping documentation synchronized with code
  • +Exceptional performance leveraging Bun's capabilities, significantly faster than traditional Node.js frameworks
  • +Clean, chainable API with minimal boilerplate compared to Express or Fastify while providing more features out of the box
  • +Active development and growing ecosystem with plugin support for modular architecture

Cons

  • Primarily designed for Bun runtime, though multi-runtime support exists performance benefits are Bun-specific
  • Smaller ecosystem and community compared to established frameworks like Express, Fastify, or NestJS, meaning fewer third-party integrations
  • Relatively new framework with potential breaking changes and less production battle-testing than mature alternatives
  • Learning curve for developers unfamiliar with TypeBox or schema-first development patterns
  • Limited resources and examples for complex enterprise patterns compared to frameworks like NestJS

Comparisons

Install

bash
npm install elysia
bash
pnpm add elysia
bash
bun add elysia