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
- Create and bootstrap a new application in a directory named
app
.
bash
bun create elysia app
- Change your working directory to the new application.
bash
cd app
- Start the development server.
bash
bun dev
- Go to localhost:3000 and you should see a page that says "Hello Elysia".
Manual Installation
- 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.
- Install packages.
bash
npm install elysia
bash
pnpm add elysia
bash
yarn add elysia
bash
bun add elysia
- If you are using TypeScript, create a
tsconfig.json
, and setstrict
totrue
:
json
{
"compilerOptions": {
"strict": true
}
}
TIP
This ensures that you are getting the full benefits of Elysia's robust type safety!
- Create the entrypoint for your Elysia server application.
typescript
import { Elysia } from 'elysia'
new Elysia().get('/', () => 'Hello, Elysia').listen(3000)
- Start the development server by running the
dev
command.
bash
bun dev
- 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.