No history yet

Introduction to ElysiaJS

Meet ElysiaJS

ElysiaJS is a web framework designed specifically for the Bun runtime. Think of a framework as a toolkit and a set of blueprints for building something. Instead of starting from scratch, a framework gives you pre-made components and a structure to follow, which makes building complex applications much faster and more organized. ElysiaJS provides this toolkit for creating high-performance web servers, APIs, and other backend services.

Its main goal is to be "ergonomic," which is a developer's way of saying it’s intuitive, comfortable, and efficient to work with. It's built to take full advantage of Bun's speed, offering a development experience that is both fast to run and fast to write.

What Makes It Different

Several features make ElysiaJS stand out. First and foremost is its performance. Because it's built on Bun, it's one of the fastest web frameworks available. This speed isn't just for show; it means your application can handle more users and more requests with less server power, which can save money and improve user experience.

Another key feature is its end-to-end type safety. ElysiaJS has excellent support for TypeScript, which means it can catch errors as you type, not when your users are trying to access your site. It automatically understands the types of your data from the request all the way to the response, reducing bugs and making your code easier to maintain.

Finally, ElysiaJS offers a unified API. You can handle standard REST APIs, GraphQL queries, and WebSockets all within the same framework, using a similar, consistent style. This simplifies your codebase, as you don't need to pull in multiple different libraries to handle different communication protocols.

FeatureElysiaJSExpress.js
RuntimeBunNode.js
PerformanceExtremely highModerate
Type SafetyBuilt-in, end-to-endRequires external libraries
Async HandlingModern (async/await)Callback-based, can be complex

Getting Started

Setting up an ElysiaJS project is straightforward, assuming you already have Bun installed on your system. To create a new project, you run a single command in your terminal.

bun create elysia my-app

This command scaffolds a new project in a directory named my-app. It sets up all the necessary files and dependencies for you. Once it's done, navigate into the new directory and start the development server.

# Navigate into your new project directory
cd my-app

# Start the development server
bun dev

Your server is now running. If you open the src/index.ts file, you'll see a very simple server configuration.

import { Elysia } from 'elysia'

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

console.log(
  `🦊 Elysia is running at http://${app.server?.hostname}:${app.server?.port}`
)

This code creates a new Elysia instance, defines a single route for the homepage (/), and tells the server to listen for requests on port 3000. If you visit http://localhost:3000 in your browser, you'll see the message "Hello Elysia".

That's all it takes to get a basic ElysiaJS server up and running. From here, you can start building out more complex APIs and services.