Skip to content

Integration with Node.js

Elysia provides a runtime adapter to run Elysia on multiple runtimes, including Node.js.

To run Elysia v2 on Node.js, install the v2 Node adapter. The v1 adapter is a different release line.

bun
bun add elysia@rc @elysia/node@rc
pnpm
pnpm add elysia@rc @elysia/node@rc
npm
npm install elysia@rc @elysia/node@rc
yarn
yarn add elysia@rc @elysia/node@rc

Then apply the Node adapter to your main Elysia instance.

import { Elysia } from 'elysia'
import { node } from '@elysia/node'
const app = new Elysia({ adapter: node() })
.get('/', () => 'Hello Elysia')
.listen(3000)

This is all you need to run Elysia on Node.js.

For the best experience, we recommend installing tsx.

tsx is a CLI that transpiles TypeScript to JavaScript with hot-reload and several more features you would expect from a modern development environment.

bun
bun add -d tsx @types/node typescript
pnpm
pnpm add -D tsx @types/node typescript
npm
npm install --save-dev tsx @types/node typescript
yarn
yarn add -D tsx @types/node typescript

Then open your package.json file, set the package to use ES modules, and add the following scripts:

{
"type": "module",
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc -p tsconfig.json",
"start": "NODE_ENV=production node dist/index.js"
}
}

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

  • dev - Start Elysia in development mode with auto-reload on code changes.
  • build - Build the application for production use.
  • start - Start a production Elysia server.

Make sure to create a tsconfig.json:

Terminal window
tsc --init

Then configure these options in tsconfig.json:

{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"types": ["node"],
"rootDir": "src",
"outDir": "dist",
"strict": true,
"skipLibCheck": true
},
"include": ["src/**/*.ts"]
}

The build script reads this configuration, including strict and the output directory. Use .js extensions when importing your own modules with NodeNext. tsx watch reloads on code changes for a similar experience to bun dev.

If your pnpm configuration does not install peer dependencies, add the peers required by Elysia v2 explicitly:

Terminal window
pnpm add typebox exact-mirror openapi-types

Type to search the documentation.

    Up arrowDown arrow to navigateEnter to selectEscape to close