Elysia is a high-performance, ergonomic web framework built specifically for the Bun runtime, emphasizing end-to-end type safety and an exceptional developer experience. It provides a comprehensive set of features for building web servers and APIs, including robust routing, middleware, declarative schema validation (powered by `@sinclair/typebox`), and integrated WebSocket support. The framework is currently stable at version 1.4.28 and maintains a rapid release cadence, frequently incorporating improvements and bug fixes, often in synergy with Bun's development. Its core differentiators include native integration with Bun for superior performance, extensive TypeScript support providing compile-time and runtime type integrity, and a strong focus on developer productivity. Elysia aims to offer a unified type system where types serve as a single source of truth across the application, from API definition to automatic documentation generation, streamlining development and reducing errors.
npm install elysiaVerified import paths — ran on the pinned version, not inferred.
This quickstart sets up a basic Elysia server with a GET route, a POST route with schema validation using `t` (TypeBox), and a simple WebSocket endpoint. It demonstrates common routing, body parsing, and schema definition patterns, then starts the server on port 3000.
Ensure all clients clear their old cookies or handle potential `401 Unauthorized` responses for routes relying on signed cookies. Implement robust cookie rotation strategies.
Review your `mount` and `group` configurations. Ensure consistent trailing slashes and prefix handling across your application. Updates in 1.4.26 address some of these issues, so upgrading is recommended.
Upgrade to Elysia 1.4.28 or newer, which includes a fix for this issue. Avoid dynamic imports directly within `.guard` in older versions or refactor to ensure routes are registered before guards are evaluated.
For optimal performance and full feature compatibility, use Elysia with the latest stable version of Bun. If using Node.js, anticipate potential compatibility issues or performance degradation.
Ensure you are running your application with `bun run <your_file.ts>` or `bun start`. If using TypeScript, ensure your `tsconfig.json` targets `ESNext` modules. Always use `import` statements for Elysia.
Verify that you are using an ESM import: `import { Elysia } from 'elysia'`. If this persists, check your `tsconfig.json`'s `module` and `moduleResolution` settings (e.g., `"module": "ESNext", "moduleResolution": "bundler"` or `"node16"`).Check the incoming request's JSON body to ensure it matches the `t.Object` schema defined for the route. For this error, the request body should be `{"name": "some string"}`.Change the port number in your `.listen()` call (e.g., `app.listen(4000)`). Alternatively, identify and terminate the process currently using the port (e.g., `lsof -i :3000` on Unix-like systems, `netstat -ano | findstr :3000` on Windows).