Registry / messaging / websocket-manager

websocket-manager

JSON →
library2.0.18jsnpmunverified

A lightweight Node.js library for managing internal and external WebSocket connections, version 2.0.18. Provides a unified interface for creating and managing WebSocket servers and clients with automatic reconnection, event handling, and connection pooling. Differentiates from raw ws or Socket.IO by focusing on simple manager patterns for multi-connection scenarios, with support for both server and client sides out of the box. Minimal dependencies and TypeScript support planned or experimental.

npm install websocket-manager
INSTALL
IMPORT
SIG · WEBSOCKET-MANAGER
W
websocket-manager
messagingjavascriptv2.0.18
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.

WebSocketManager
import { WebSocketManager } from 'websocket-manager'
const WebSocketManager = require('websocket-manager')
Package is ESM-only since v2. Use named import, not default.
createServer
import { createServer } from 'websocket-manager'
const createServer = require('websocket-manager').createServer
Named export, not on default object.
WebSocketClient
import { WebSocketClient } from 'websocket-manager'
import WebSocketClient from 'websocket-manager'
Not a default export; use named import.

Demonstrates server creation, client connection, and connection management with WebSocketManager.

import { WebSocketManager, createServer, WebSocketClient } from 'websocket-manager'; // Create a WebSocket server on port 8080 const server = createServer({ port: 8080 }); server.on('connection', (ws) => { console.log('Client connected'); ws.send('Welcome!'); }); // Create a client that connects to the server const client = new WebSocketClient('ws://localhost:8080'); client.on('open', () => { console.log('Connected to server'); client.send('Hello server!'); }); client.on('message', (data) => { console.log('Received:', data.toString()); }); // Use the manager to handle multiple connections const manager = new WebSocketManager(); manager.addConnection('client1', client); manager.broadcast('Hello everyone!');
Debug
Known issues
breakingVersion 2.0 changed from CommonJS to ESM-only. require() will fail with ERR_REQUIRE_ESM.
fix
Use import statements and ensure your project is ESM (type: 'module' in package.json).
affects: >=2.0.0
deprecatedThe method addConnection() is deprecated in favor of add()
fix
Replace manager.addConnection('name', ws) with manager.add('name', ws).
affects: >=2.0.0
gotchaThe createServer function does not start the server automatically before v2.0.10; you must call server.listen() explicitly.
fix
Upgrade to >=2.0.10 or call server.listen() after creation.
affects: <2.0.10
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module not supported.
Using CommonJS require() with ESM-only package version 2.x.
fix
Switch to import syntax or use dynamic import().
TypeError: WebSocketManager is not a constructor
Incorrect import style (expected default import but package exports named exports).
fix
Use import { WebSocketManager } from 'websocket-manager' instead of import WebSocketManager from 'websocket-manager'.
Error: listen EADDRINUSE :::8080
Port 8080 is already in use by another process or previous server instance.
fix
Choose a different port or close existing server before starting.
Upgrade
Version history
2.0.18latest on npm
Audit
Dependencies
wsrequiredCore WebSocket implementation used for both server and client connections.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
websocket-manager — npm install websocket-manager · libregistry