Licence
MIT
Version
0.9.13
Deps
1
Size
78 kB
Vulns
0
Weekly
3.9K
@nexusts/ws
NexusTS WebSockets — WebSocket gateways with Bun's built-in
Bun.servewebsocket. Rooms, broadcast, and lifecycle decorators.
Features
- Bun native — uses
Bun.servewebsocket (no ws package needed) - Decorators —
@WebSocketGateway(path),@OnWebSocketOpen,@OnWebSocketMessage,@OnWebSocketClose - Rooms —
joinRoom,leaveRoom,broadcastToRoom - Cloudflare Workers — compatible via adapter
Install
This module is part of the NexusTS monorepo. Each module is published as its own npm package under the @nexusts/ scope.
Most apps start with just the core:
bun add @nexusts/coreThen add this module only if you need it:
bun add @nexusts/wsPeer dependencies
None. Bun's WebSocket runtime is built in — no ws package needed.
Quick start
import { WebSocketModule, WebSocketGateway, OnWebSocketMessage } from "@nexusts/ws";
import { Module, Injectable } from "@nexusts/core";
@Injectable()
@WebSocketGateway("/chat")
class ChatGateway {
@OnWebSocketMessage("message")
onMessage(client: any, data: { text: string }) {
client.send(`Echo: ${data.text}`);
}
}
@Module({
imports: [WebSocketModule.forRoot({ gateways: [ChatGateway] })],
})
class AppModule {}See the user guide and the example app for a working demo.
License
MIT — see the root LICENSE.