Why are Bun and ElysiaJS taking the Dev community by storm?
Tired of configuring tsconfig.json or slow package installations on Node.js? The Bun + ElysiaJS combo is a formidable alternative. You’ll no longer have to wait forever for npm install to finish.
I started implementing Bun into real-world microservices about 6 months ago. My first impression can be summed up in one word: Fast. Bun isn’t just a runtime; it comes with a built-in package manager, test runner, and bundler. Meanwhile, ElysiaJS was born to maximize this power with a philosophy of maximum speed and absolute Type Safety.
After refactoring an API system from Express to Elysia, I noticed that boilerplate code was reduced by nearly 40%. Specifically, “undefined is not a function” errors on the Frontend almost vanished thanks to its smart type synchronization mechanism.
The Core Power of the Bun Runtime
Instead of using V8 like Node.js, Bun chooses JavaScriptCore (JSC) — the engine behind the Safari browser. JSC has the advantage of fast startup times and extremely tight memory management.
A huge plus is that Bun supports running .ts files directly. You just need to type bun run index.ts and you’re good to go. No more struggling with complex Babel or esbuild configurations like before.
Hands-on: Building a REST API in 5 Minutes
First, install Bun via the terminal:
curl -fsSL https://bun.sh/install | bash
Next, initialize an ElysiaJS project with a single command:
bun create elysia my-api
cd my-api
Minimalist Server Structure
Open src/index.ts, and you’ll see Elysia’s coding style is very modern, similar to Fastify but even cleaner:
import { Elysia, t } from 'elysia'
const app = new Elysia()
.get('/', () => 'Hello from itfromzero.com!')
.post('/user', ({ body }) => body, {
body: t.Object({
name: t.String(),
age: t.Number()
})
})
.listen(3000)
console.log(`Server running at: ${app.server?.hostname}:${app.server?.port}`);
The “killer feature” here is the t object (TypeBox). It acts as a gatekeeper. If a client sends a request missing the name field, Elysia automatically blocks it and returns a 400 error immediately. You don’t need to write a single line of manual validation logic.
Automated Documentation with Swagger
Writing APIs without documentation is a nightmare for Frontend teams. With Elysia, you get Swagger UI in just seconds of setup.
Install the plugin:
bun add @elysiajs/swagger
Integrate into the code:
import { Elysia } from 'elysia'
import { swagger } from '@elysiajs/swagger'
new Elysia()
.use(swagger())
.get('/posts', () => [{ id: 1, title: 'Learning Bun with IT From Zero' }])
.listen(3000)
Access localhost:3000/swagger, and you’ll see a professional API testing interface, saving you hours of manual documentation.
The Eden Treaty Trick: Seamless Frontend-Backend Connection
This is my favorite feature. Usually, when the Backend changes data types, the Frontend can easily break if it’s not updated in time.
Eden Treaty completely solves this problem by allowing the Frontend to “inherit” all types from the Backend. You no longer need to manually copy-paste interfaces.
In the Backend project, simply export the app type:
export type App = typeof app;
On the Frontend (React/Next.js):
import { edenTreaty } from '@elysiajs/eden'
import type { App } from '../backend/src/index'
const client = edenTreaty<App>('http://localhost:3000')
// Intellisense will suggest the exact endpoint and data types
const { data } = await client.hello.get()
In a real project with over 100 endpoints, refactoring variable names becomes extremely safe. If you change a field name on the Backend, the IDE will immediately show a red error in the Frontend code. This is the power of End-to-End Type Safety.
Real-world Experience Working with Bun
- Bun SQLite: For small apps or caching needs, use the built-in SQLite. Its query speed is significantly faster than traditional drivers.
- Context Management: Prioritize using Elysia’s
.state()and.derive()to manage user sessions instead of using global variables. - Testing Speed:
bun testis about 10-20 times faster than JSON. Leverage it to maintain a short feedback loop and code with more confidence.
Many worry that Bun isn’t stable enough yet. However, since version 1.x, Bun has truly matured and is ready for production environments. Don’t let yourself get stuck with outdated and slow tools.
Experiencing ElysiaJS and Bun isn’t just about following trends. It’s about optimizing productivity and eliminating silly programming errors. Try creating a small project today to feel the smoothness of this combo!

