Registry / networking / websocket13

websocket13

JSON →
library4.1.0jsnpmunverified

A pure-JavaScript WebSocket protocol 13 (RFC 6455) implementation for Node.js with no native or heavy dependencies. Current stable version is 4.1.0, released with moderate cadence. It supports both client and server modes, requires Node.js >=12.22.0. Key differentiator: zero native dependencies, lightweight, and compatible with the standard WebSocket API subset. Not suitable for browsers (Node-only).

npm install websocket13
INSTALL
IMPORT
SIG · WEBSOCKET13
W
websocket13
networkingjavascriptv4.1.0
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.

WebSocket
import { WebSocket } from 'websocket13'
const WebSocket = require('websocket13').WebSocket
ESM import is recommended; CommonJS require works but may have issues with named exports in some bundlers.
WebSocketServer
import { WebSocketServer } from 'websocket13'
const WebSocketServer = require('websocket13').WebSocketServer
Named export; do not use default import.
createWebSocketStream
import { createWebSocketStream } from 'websocket13'
import createWebSocketStream from 'websocket13'
This is a named export, not default. Function returns a Duplex stream.

Creates a WebSocket client connection to a server, sends a message, logs received data, and closes.

import { WebSocket } from 'websocket13'; const ws = new WebSocket('ws://localhost:8080', [], { timeout: 5000 }); ws.on('open', () => { ws.send('Hello server!'); }); ws.on('message', (data) => { console.log('Received:', data.toString()); ws.close(); }); ws.on('error', (err) => console.error('WebSocket error:', err));
Debug
Known issues
breakingIn v4, the 'WebSocket' constructor no longer accepts a third argument for protocols as array; now uses object options.
fix
Use syntax: new WebSocket(url, [], { headers: {...} })
affects: >=4.0.0
breakingThe 'on('message')' callback now receives a Buffer instead of a String for binary messages in v4.
fix
Check if data is Buffer or String and decode accordingly.
affects: >=4.0.0
deprecatedThe 'WebSocketClient' class alias is deprecated in v4, use 'WebSocket' directly.
fix
Replace 'WebSocketClient' with 'WebSocket'.
affects: >=4.0.0
gotchaAutomatic reconnection is not built-in; you must manually handle reconnection on 'close' event.
fix
Implement reconnection logic with exponential backoff.
affects: >=0.0.0
gotchaThe library is Node-only and does not work in browser environments; it uses Node.js net and tls modules.
fix
Use 'ws' or native WebSocket for browser code.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: websocket13__WEBPACK_IMPORTED_MODULE_0__ is not a constructor
Default import used when named export is required.
fix
Use import { WebSocket } from 'websocket13'
Error: connect ECONNREFUSED ::1:8080
No server listening on the specified host:port or wrong URL.
fix
Ensure WebSocket server is running and URL is correct (ws:// or wss://).
Upgrade
Version history
4.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
30 hits · last 30 days
node
28
OpenAI (training)
1
Resources
websocket13 — npm install websocket13 · libregistry