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:
curl https://bun.sh/install | bash
curl https://bun.sh/install | bash
Automatic Installation â
We recommend starting a new Elysia server using bun create elysia
, which sets up everything automatically.
bun create elysia app
bun create elysia app
Once done, you should see the folder name app
in your directory.
cd app
cd app
Start a development server by:
bun dev
bun dev
Navigate to localhost:3000 should greet you with "Hello Elysia".
TIP
Elysia ships you with dev
command to automatically reload your server on file change.
Manual Installation â
To manually create a new Elysia app, install Elysia as a package:
bun add elysia
bun add elysia
Open your package.json
file and add the following scripts:
{
"scripts": {
"dev": "bun --watch src/index.ts",
"build": "bun build src/index.ts",
"start": "NODE_ENV=production bun src/index.ts",
"test": "bun test"
}
}
{
"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.
If you are using TypeScript, make sure to create, and update tsconfig.json
to include compilerOptions.strict
to true
:
{
"compilerOptions": {
"strict": true
}
}
{
"compilerOptions": {
"strict": true
}
}
Structure â
Here's the recommended file structure for Elysia if you don't strictly prefer a specific convention:
- src - Any file that associate with development of Elysia server.
- index.ts - Entry point for your Elysia server, ideal place for setting global plugin
- setup.ts - Composed of various plugins to be used as a Service Locator
- controllers - Instances which encapsulate multiple endpoints
- libs - Utility functions
- models - Data Type Objects (DTOs) for Elysia instance
- types - Shared TypeScript type if needed
- test - Test file for Elysia server