Elysia - Ergonomic Framework for Humans | ElysiaJS

ID: 2106https://elysiajs.com/
Source

Elysia - Ergonomic Framework for Humans

Elysia is an ergonomic framework for Humans.
With end‑to‑end type safety and great developer experience.
Elysia is familiar, fast, and has first‑class TypeScript support with well‑thought integration between services whether it’s tRPC, Swagger or WebSocket.


Hero

bun create elysia app

Get Started/at-glance

See why developers love Elysia


The first production ready, and most loved Bun framework

Trusted by team at


Made for Humans

Design for Humans

Our goal is to design an ergonomic, sensible, and productive framework that even beginners can use easily.
Designed to avoid unnecessary complexity and type complexity for you to focus on building.
A framework that feels just like JavaScript.

import { Elysia, file } from 'elysia'

new Elysia()
	.get('/', 'Hello World')
	.get('/image', file('mika.webp'))
	.get('/stream', function* () {
		yield 'Hello'
		yield 'World'
	})
	.ws('/realtime', {
		message(ws, message) {
			ws.send('got:' + message)
		}
	})
	.listen(3000)

Summary

FeatureWhat you returnExample
Just returnA string, number, or complex JSONreturn { message: 'hello' }
File supportfile('path')file('image.png')
Stream responseyield a valuefunction* () { yield 'Hello'; yield 'World'; }
Data in real‑timeWebSocketws('/realtime', { message(ws, msg) { ws.send('got:' + msg); } })

Benchmark

FrameworkReq/s
Elysia (Bun)2,454,631
Gin (Go)676,019
Spring (Java)506,087
Fastify (Node)415,600
Express (Node)113,117
Nest (Node)105,064

Measured in requests/second. Result from https://www.techempower.com/benchmarks/#hw=ph&test=plaintext§ion=data-r22 Round 22 (2023‑10‑17).


Your code, your runtime

  • Elysia is optimized for Bun but not vendor‑lock‑in.
  • Built on Web‑Standard – run Elysia anywhere.

Type Safety

Best in Class – Type Safety

import { Elysia, t } from 'elysia'

new Elysia()
	.post('/user', ({ body }) => {
		return body, {
			body: t.Object({
				name: t.Literal('SaltyAom'),
				age: t.Number(),
				friends: t.Array(t.String())
			})
		}
	})

Bring your own Validator

Elysia offers a built‑in validator, but you can also bring your favorite validator, like Zod, Valibot, ArkType, Effect, and more.

Code examples

TypeBox

import { Elysia, t } from 'elysia'

new Elysia()
	.post('/user', ({ body }) => {
		return body, {
			body: t.Object({
				name: t.Literal('SaltyAom'),
				age: t.Number(),
				friends: t.Array(t.String())
			})
		}
	})

Zod

import { Elysia } from 'elysia'
import { z } from 'zod'

new Elysia()
	.post('/user', ({ body }) => {
		return body, {
			body: z.object({
				name: z.literal('SaltyAom'),
				age: z.number(),
				friends: z.array(z.string())
			})
		}
	})

Valibot

import { Elysia } from 'elysia'
import { validator } from '@valibot/valibot'

new Elysia()
	.post('/user', ({ body }) => {
		return body, {
			body: validator({
				name: validator.string().equals('SaltyAom'),
				age: validator.number(),
				friends: validator.array(validator.string())
			})
		}
	})

ArkType

import { Elysia } from 'elysia'
import { z } from 'arktype'

new Elysia()
	.post('/user', ({ body }) => {
		return body, {
			body: z({
				name: 'SaltyAom',
				age: z.number(),
				friends: z.string().array()
			})
		}
	})

Effect

import { Elysia } from 'elysia'
import { t } from '@effect/schema/Schema'

new Elysia()
	.post('/user', ({ body }) => {
		return body, {
			body: t.struct({
				name: t.literal('SaltyAom'),
				age: t.number,
				friends: t.array(t.string)
			})
		}
	})

Other Sections (placeholders for the rest of the page)

  • Further documentation, tutorials, API reference, and advanced features would follow in the same format, with headings, paragraphs, code blocks, and interactive snippets converted into Markdown.