Registry / messaging / adonisjs-websocket

adonisjs-websocket

JSON →
library0.2.3jsnpmunverified

Websocket provider for AdonisJS v6, version 0.2.3, actively maintained. Provides WebSocket route registration via router.ws(), middleware support, broadcasting, and controller-based handling. Integrates seamlessly with AdonisJS core, auth, and HTTP server. Alternative to socket.io with tighter AdonisJS integration.

npm install adonisjs-websocket
INSTALL
IMPORT
SIG · ADONISJS-WEBSOCKET
A
adonisjs-websocket
messagingjavascriptv0.2.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WebSocketContext
import type { WebSocketContext } from 'adonisjs-websocket'
import { WebSocketContext } from 'adonisjs-websocket'
WebSocketContext is only a type, use type import.
router.ws()
router.ws('/path', handler)
Registered via AdonisJS router, no explicit import needed.
ws.broadcast()
await ws.broadcast('message')
ws.broadcast('message')
broadcast() is async, must be awaited.

Install the package, define a WebSocket route, and handle messages.

// install node ace add adonisjs-websocket // start/routes.ts router.ws('/ws', ({ ws }) => { ws.on('message', (message) => { ws.send('Received: ' + message.toString()) }) ws.on('close', () => { console.log('Connection closed') }) ws.send('Hello! Your id is ' + ws.id) })
Debug
Known issues
breakingNode.js >=20.6.0 required
fix
Upgrade Node.js to v20.6.0 or later.
affects: >=0.0.0
breakingRequires @adonisjs/core ^6.2.0 and @adonisjs/http-server ^7.0.2
fix
Ensure AdonisJS v6.2+ and http-server v7.0.2+ are installed.
affects: >=0.0.0
gotchabroadcast() is async, must be awaited
fix
Use await ws.broadcast() inside async handler.
affects: >=0.0.0
gotchaWebSocketContext is a type only, not a runtime value
fix
Use import type { WebSocketContext } from 'adonisjs-websocket'.
affects: >=0.0.0
gotchaWebSocket route handlers must be async if using broadcast() or other async operations
fix
Define handler as async ({ ws }) => { ... }.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'adonisjs-websocket' or its corresponding type declarations.
Package not installed or missing peer deps.
fix
Run `node ace add adonisjs-websocket` to install and configure.
TypeError: ws.broadcast is not a function
broadcast() used without await or on non-WebSocket context.
fix
Ensure handler is async and await ws.broadcast().
Error: Cannot find module '@adonisjs/core'
Missing or incompatible peer dependency.
fix
Install @adonisjs/core v6.2+ and @adonisjs/http-server v7.0.2+.
Upgrade
Version history
0.2.3latest on npm
Audit
Dependencies
@adonisjs/corerequiredRequired peer dependency for AdonisJS framework integration
@adonisjs/http-serverrequiredRequired peer dependency for HTTP server context
Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
adonisjs-websocket — npm install adonisjs-websocket · libregistry