Registry / devops / liqd-websocket

liqd-websocket

JSON →
library1.2.3jsnpmunverified

liqd-websocket v1.2.3 is a lightweight WebSocket library for Node.js, offering a simple API for creating WebSocket clients and servers. It is designed for stability with infrequent releases. Differentiators include a minimal footprint and dependency on Node.js native 'crypto' for WebSocket handshake validation. It supports both server and client modes with event-driven messaging.

npm install liqd-websocket
INSTALL
IMPORT
SIG · LIQD-WEBSOCKET
L
liqd-websocket
devopsjavascriptv1.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.

WebSocket
import WebSocket from 'liqd-websocket'
const WebSocket = require('liqd-websocket');
Default import is the main constructor. CommonJS require is also supported.
createServer
import { createServer } from 'liqd-websocket'
const { createServer } = require('liqd-websocket');
Named export for creating a WebSocket server.
connect
import { connect } from 'liqd-websocket'
const { connect } = require('liqd-websocket');
Named export for connecting to a WebSocket server.

Creates a WebSocket server on port 8080 and handles client connections, messages, and disconnection.

import { createServer } from 'liqd-websocket'; const server = createServer({ port: 8080 }); server.on('connection', (ws) => { console.log('Client connected'); ws.send('Hello from server'); ws.on('message', (data) => { console.log('Received:', data.toString()); }); ws.on('close', () => console.log('Client disconnected')); });
Debug
Known issues
gotchaThe WebSocket server does not support per-message deflate compression by default.
fix
Consider using a library like 'ws' if compression is required.
affects: <2.0.0
gotchaThe 'message' event callback receives a Buffer, not a string. Must call .toString() for text.
fix
Use data.toString() inside the event handler.
affects: >=1.0.0
deprecatedThe 'send' method only accepts string or Buffer. Objects will not be automatically serialized.
fix
Manually JSON.stringify data before sending.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: server.on is not a function
Using createServer incorrectly: it returns a WebSocket.Server instance, but if not called with 'new', it may return undefined.
fix
Ensure you use createServer({ port: 8080 }) without additional new.
Error: Unexpected server response: 426
The WebSocket server requires an upgrade request; the client connection URL path may be missing or the server expects a specific path.
fix
Check the server path option: createServer({ port: 8080, path: '/ws' }) and connect accordingly.
Upgrade
Version history
1.2.3latest on npm
Audit
Dependencies
cryptorequiredUsed for WebSocket handshake validation (SHA-1 hash)
Agent activity
3 hits · last 30 days
node
2
Amazon
1
Resources
liqd-websocket — npm install liqd-websocket · libregistry