Skip to main content
Elysia is a TypeScript web framework built for Bun. It takes full advantage of Bun’s HTTP, file system, and hot reloading APIs, and is one of the fastest Bun HTTP frameworks.

Quick start

Scaffold a new Elysia project with bun create:
bun create elysia my-app
cd my-app
bun run dev

Manual setup

1

Install Elysia

bun add elysia
2

Create a server

src/index.ts
import { Elysia } from "elysia";

const app = new Elysia()
  .get("/", () => "Hello Elysia")
  .listen(3000);

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

Run the server

bun run src/index.ts

Routing

Elysia uses a chainable API for defining routes:
import { Elysia } from "elysia";

const app = new Elysia()
  .get("/", () => "Hello!")
  .get("/users/:id", ({ params }) => `User: ${params.id}`)
  .post("/users", ({ body }) => body)
  .put("/users/:id", ({ params, body }) => ({ id: params.id, ...body }))
  .delete("/users/:id", ({ params }) => `Deleted ${params.id}`)
  .listen(3000);

Schema validation

Elysia provides end-to-end type safety through its t schema validation module. Schemas are validated at runtime and inferred as TypeScript types automatically:
import { Elysia, t } from "elysia";

const app = new Elysia()
  .post("/sign-in", ({ body }) => body, {
    body: t.Object({
      username: t.String(),
      password: t.String({ minLength: 8 }),
    }),
  })
  .listen(3000);
If the request body does not match the schema, Elysia returns a 400 Bad Request with a descriptive error.

Middleware (lifecycle hooks)

Use Elysia’s lifecycle hooks to run code before or after route handlers:
import { Elysia } from "elysia";

const app = new Elysia()
  .onRequest(({ request }) => {
    console.log(`${request.method} ${request.url}`);
  })
  .onError(({ code, error }) => {
    if (code === "NOT_FOUND") return new Response("Not found", { status: 404 });
  })
  .get("/", () => "OK")
  .listen(3000);

Plugins

Elysia has a plugin system for sharing routes, middleware, and state across your app:
import { Elysia } from "elysia";

const auth = new Elysia({ name: "auth" })
  .derive({ as: "scoped" }, ({ headers }) => ({
    user: headers["x-user"] ?? "anonymous",
  }))
  .get("/me", ({ user }) => user);

const app = new Elysia()
  .use(auth)
  .get("/", () => "Hello!")
  .listen(3000);
Popular community plugins include:
  • @elysiajs/bearer — Bearer token extraction
  • @elysiajs/cors — CORS configuration
  • @elysiajs/jwt — JWT authentication
  • @elysiajs/swagger — OpenAPI / Swagger UI generation
  • @elysiajs/trpc — tRPC adapter
Install any of them with bun add:
bun add @elysiajs/cors @elysiajs/swagger
See the Elysia documentation for the complete API reference, including WebSocket support, file uploads, and server-sent events.

Build docs developers (and LLMs) love