Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# 1.4.0 - 27 July 2025

### Added
- Full WebSocket support with publish/subscribe API
- WebSocket lifecycle events (open, message, close)
- `UwsWebSocketWrapper` class for Elysia WebSocket compatibility

### Changed
- **BREAKING**: Upgraded to uWebSockets.js for high performance
- Refactored server architecture for Bun runtime compatibility
- Enhanced streaming request/response handling

### Improved
- Near 1:1 API compatibility with Bun adapter
- Better error handling for WebSocket upgrades
- Streamlined server setup and route registration

### Technical
- Added `createWebRequest` and `applyResponse` utilities
- Integrated with Elysia's WebSocket validation system
- Support for binary/text WebSocket messages

# 1.3.0 - 27 May 2025
Change:
- use WebStandard Compatibility via `@hono/node-server`
Expand Down
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
# @elysiajs/node
Adapter for [elysia](https://github.com/elysiajs/elysia) to use Elysia in Nodejs environment.

A high-performance, fully-featured adapter for [Elysia](https://github.com/elysiajs/elysia) to run on the Node.js environment using `uWebSockets.js`.

This adapter brings the raw performance of `uWebSockets.js` to Node.js, providing a server environment that is architecturally consistent with Elysia's native Bun runtime.

## Features

- 🚀 High-performance HTTP server
- 🔌 **Full WebSocket Support**: Includes the powerful `publish/subscribe` API.
- streamed bodies: generator support
- 🦊 Near 1:1 API compatibility with the Bun adapter.

## Installation

```bash
bun add @elysiajs/node
```

## Example

```typescript
import { Elysia } from 'elysia'
import { node } from '@elysiajs/node'

const app = new Elysia({ adapter: node() })
.get('/', () => 'Hello Node!')
.listen(3000)
.get('/', () => 'Hello Node!')
.listen(3000)
```

### Note
Node adapter is not feature complete yet. Some features are not supported, such as:
- not support `ws` method
166 changes: 81 additions & 85 deletions bun.lock

Large diffs are not rendered by default.

38 changes: 31 additions & 7 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Elysia, file } from 'elysia'
import { cors } from '@elysiajs/cors'
import { swagger } from '@elysiajs/swagger'

import swagger from '@elysiajs/swagger'
import { Elysia, file } from 'elysia'
import { node } from '../src'

const app = new Elysia({
Expand All @@ -12,12 +11,37 @@ const app = new Elysia({
.get('/image', async () => file('test/kyuukurarin.mp4'))
.get('/generator', async function* () {
for (let i = 0; i < 100; i++) {
await new Promise(resolve => setTimeout(resolve, 10))
yield "A"
await new Promise((resolve) => setTimeout(resolve, 10))
yield 'A'
}
})
.get('/stream', async function* () {
for (let i = 0; i < 10; i++) {
yield `Chunk ${i}\n`
await new Promise((resolve) => setTimeout(resolve, 100))
}
})
.post('/', ({ body }) => body, {
type: 'json'
})
.get('/', () => 'ok')
.listen(3000)
.get('/', () => 'Hello from uWebSockets.js!')
.ws('/ws', {
open(ws) {
console.log('WebSocket connected')
ws.subscribe('chat')
ws.publish('chat', 'Someone joined the chat!')
},
message(ws, message) {
console.log('Received message:', message)
ws.publish('chat', `Echo: ${message}`)
},
close(ws) {
console.log('WebSocket disconnected')
}
})
.listen(3000, (server) => {
console.log(`🦊 Elysia is running at ${server.hostname}:${server.port}`)
console.log(
`WebSocket available at ws://${server.hostname}:${server.port}/ws`
)
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@elysiajs/node",
"version": "1.3.0",
"description": "Plugin for Elysia for retreiving Bearer token",
"version": "1.4.0",
"description": "High-performance Node.js adapter for Elysia using uWebSockets.js",
"license": "MIT",
"scripts": {
"dev": "tsx --watch ./example/index.ts",
Expand All @@ -11,7 +11,7 @@
"release": "npm run build && npm run test && npm publish --access public"
},
"dependencies": {
"@hono/node-server": "^1.14.3"
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.44.0"
},
"peerDependencies": {
"elysia": ">= 1.3.3"
Expand Down
Loading