Registry / messaging / nodejs-websocket

nodejs-websocket

JSON →
library1.7.2jsnpmunverified

nodejs-websocket is a minimal WebSocket server and client library for Node.js, current stable version 1.7.2. It provides a simple API for creating WebSocket servers and clients with support for text and binary frames. Released on a low cadence (last update 2019), it focuses on lightweight implementation over full RFC compliance. Unlike ws or socket.io, it lacks automatic reconnection, compression, and extensive protocol support. It uses Node's net/tls modules and is suitable for basic WebSocket use cases.

npm install nodejs-websocket
INSTALL
IMPORT
SIG · NODEJS-WEBSOCKET
N
nodejs-websocket
messagingjavascriptv1.7.2
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.

default
const ws = require('nodejs-websocket')
import ws from 'nodejs-websocket'
This package does not support ES modules; must use CommonJS require.
createServer
const { createServer } = require('nodejs-websocket')
import { createServer } from 'nodejs-websocket'
CommonJS destructured require; ES import not supported.
connect
const { connect } = require('nodejs-websocket')
const { connect } = require('nodejs-websocket').default
No default export; direct destructure from require.

Creates a WebSocket server that echoes uppercase text, and a client that connects and sends a message.

const ws = require('nodejs-websocket'); const server = ws.createServer(conn => { console.log('New connection'); conn.on('text', str => { console.log('Received ' + str); conn.sendText(str.toUpperCase() + '!!!'); }); conn.on('close', (code, reason) => { console.log('Connection closed'); }); }).listen(8001, () => console.log('Server listening on port 8001')); // Client side const client = ws.connect('ws://localhost:8001', {}, () => { console.log('Connected'); client.sendText('Hello'); client.on('text', str => console.log('Received: ' + str)); });
Debug
Known issues
gotchaEvent names are 'text', 'binary', 'close', 'connect' — not 'message' as in standard WebSocket API.
fix
Use conn.on('text', handler) instead of conn.on('message', handler).
affects: >=1.0
gotchaConnection object 'sendText' and 'sendBinary' methods exist, but 'send' is not a method.
fix
Use conn.sendText(str) or conn.sendBinary(buffer) explicitly.
affects: >=1.0
deprecatedPackage has not been updated since 2019; may have unpatched vulnerabilities.
fix
Consider migrating to 'ws' or 'uWebSockets.js' for active maintenance and security fixes.
affects: >=1.0
gotchaNo built-in ping/pong heartbeat; connections may drop silently without keep-alive.
fix
Implement custom ping/pong or use a library like 'ws' which supports it natively.
affects: >=1.0
Errors
Common errors & fixes
Error: Cannot find module 'nodejs-websocket'
Package not installed in node_modules when using require.
fix
Run 'npm install nodejs-websocket' in your project directory.
TypeError: conn.sendText is not a function
Using 'send' instead of 'sendText' or 'sendBinary'.
fix
Replace 'conn.send(str)' with 'conn.sendText(str)'.
Upgrade
Version history
1.7.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
nodejs-websocket — npm install nodejs-websocket · libregistry