Skip to content

Quick Start

Elysia is optimized for Bun, which is a JavaScript runtime that aims to be a drop-in replacement for Node.js.

You can install Bun with the command below:

bash
curl https://bun.sh/install | bash

INFO

Read more about Bun from their official documentation.

Automatic Installation

  1. Create and bootstrap a new application in a directory named app.
bash
bun create elysia app
  1. Change your working directory to the new application.
bash
cd app
  1. Start the development server.
bash
bun dev
  1. Go to localhost:3000 and you should see a page that says "Hello Elysia".

Manual Installation

  1. Create a package.json and add the following scripts.
json
{
  "scripts": {
    "dev": "bun --watch src/index.ts",
    "build": "bun build src/index.ts",
    "start": "NODE_ENV=production bun src/index.ts",
    "test": "bun test"
  }
}

These scripts refer to the different stages of developing an application:

  • dev - Start Elysia in development mode with auto-reload on code change.
  • build - Build the application for production usage.
  • start - Start an Elysia production server.
  1. Install packages.
bash
npm install elysia
bash
pnpm add elysia
bash
yarn add elysia
bash
bun add elysia
  1. If you are using TypeScript, create a tsconfig.json, and set strict to true:
json
{
  "compilerOptions": {
    "strict": true
  }
}

TIP

This ensures that you are getting the full benefits of Elysia's robust type safety!

  1. Create the entrypoint for your Elysia server application.
typescript
import { Elysia } from 'elysia'

new Elysia().get('/', () => 'Hello, Elysia').listen(3000)
  1. Start the development server by running the dev command.
bash
bun dev
  1. Go to localhost:3000 and you should see a page that says "Hello Elysia".

Project Structure

Here is a simple project structure for getting started with development:

md
📁 src - Source code for your Elysia server application.
│   ├── 🇹🇸 index.ts - Entry point for your application.
│   ├── 🇹🇸 setup.ts - Various plugins to be used as a Service Locator.
│   │── 📁 controllers - Elysia instances that encapsulate endpoints.
│   │── 📁 libs - Utilities.
│   │── 📁 models - Data Transfer Objects (DTOs) for your application.
│   └── 📁 types - Shared TypeScript types, if needed.
└── 📁 tests - Test for your Elysia server application.