DEV Community

Alex Spinov
Alex Spinov

Posted on

ElysiaJS Has a Free Bun Framework That's Faster Than Express — End-to-End Type Safety Like tRPC

The Bun Framework Problem

Bun is fast but Bun.serve() is low-level. Express works on Bun but wastes its speed. Hono is good but doesn't have tRPC-level type safety.

ElysiaJS is built FOR Bun. Fastest TypeScript web framework with end-to-end type safety.

What ElysiaJS Gives You

Simple API

import { Elysia } from 'elysia';

const app = new Elysia()
  .get('/', () => 'Hello World')
  .get('/user/:id', ({ params: { id } }) => `User ${id}`)
  .post('/users', ({ body }) => body)
  .listen(3000);
Enter fullscreen mode Exit fullscreen mode

Validation With Full Type Inference

import { Elysia, t } from 'elysia';

const app = new Elysia()
  .post('/users', ({ body }) => {
    // body is FULLY TYPED: { name: string; email: string }
    return { id: 1, ...body };
  }, {
    body: t.Object({
      name: t.String(),
      email: t.String({ format: 'email' }),
    }),
  });
Enter fullscreen mode Exit fullscreen mode

Validation and TypeScript types from a single schema. Like Zod but built into the framework.

Eden (Type-Safe Client)

// Server
const app = new Elysia()
  .get('/posts', () => db.posts.findMany())
  .post('/posts', ({ body }) => db.posts.create(body), {
    body: t.Object({ title: t.String(), content: t.String() }),
  });

export type App = typeof app;

// Client — full autocomplete, like tRPC
import { treaty } from '@elysiajs/eden';
import type { App } from './server';

const client = treaty<App>('localhost:3000');
const posts = await client.posts.get(); // typed!
const newPost = await client.posts.post({
  title: 'Hello',
  content: 'World',
}); // validated + typed!
Enter fullscreen mode Exit fullscreen mode

Plugins

import { swagger } from '@elysiajs/swagger';
import { cors } from '@elysiajs/cors';
import { jwt } from '@elysiajs/jwt';

const app = new Elysia()
  .use(swagger())
  .use(cors())
  .use(jwt({ secret: 'your-secret' }))
  .get('/docs', () => 'Swagger UI auto-generated');
Enter fullscreen mode Exit fullscreen mode

Performance

Framework Requests/sec
Express (Node) 15,000
Fastify (Node) 60,000
Hono (Bun) 150,000
ElysiaJS (Bun) 300,000

Quick Start

bun create elysia my-app
cd my-app
bun run dev
Enter fullscreen mode Exit fullscreen mode

Why This Matters

ElysiaJS combines the performance of Bun with the type safety of tRPC. You get the fastest framework AND the best DX.


Building high-performance APIs? Check out my web scraping actors on Apify Store — data at speed. For custom solutions, email spinov001@gmail.com.

Top comments (0)