Registry / messaging / yws-stream

yws-stream

JSON →
library1.0.0jsnpmunverified

Node.js native stream wrapper for WebSocket connections, version 1.0.0. Enables standard Node.js stream APIs (pipe, read, write) over WebSocket transport. Minimal footprint with no external dependencies. Differentiates by offering a simple, low-level stream interface directly on WebSocket instances, unlike higher-level libraries such as ws or socket.io.

npm install yws-stream
INSTALL
IMPORT
SIG · YWS-STREAM
Y
yws-stream
messagingjavascriptv1.0.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.

default
import WebSocketStream from 'yws-stream'
import { WebSocketStream } from 'yws-stream'
Package uses default export; named import will result in undefined.
WebSocket
import WebSocket from 'ws'
import WebSocket from 'yws-stream'
yws-stream wraps WebSocket objects; you need a WebSocket library like 'ws' separately.
require
const WebSocketStream = require('yws-stream')
const { WebSocketStream } = require('yws-stream')
CommonJS require yields the default export directly.

Shows creating a WebSocketStream from a WebSocket instance and using it with Node.js stream methods (on data, write, pipe).

import WebSocket from 'ws'; import WebSocketStream from 'yws-stream'; const ws = new WebSocket('wss://example.com/socket'); const stream = new WebSocketStream(ws); // Read from stream stream.on('data', (chunk) => { console.log('Received:', chunk.toString()); }); // Write to stream stream.write('Hello server!'); // Pipe from a readable source const { Readable } = require('stream'); const source = Readable.from(['message1', 'message2']); source.pipe(stream);
Debug
Known issues
gotchaWebSocketStream is not a constructor; use 'new' keyword.
fix
Use 'const stream = new WebSocketStream(ws)' correctly.
affects: >=1.0.0
gotchaThe stream does not auto-connect; the WebSocket must already be open.
fix
Ensure WebSocket is open before creating the stream.
affects: >=1.0.0
gotchaBackpressure is not fully supported; writing faster than WebSocket can send may buffer indefinitely.
fix
Use 'stream.write('data')' and check return value; consider using a transform stream for flow control.
affects: >=1.0.0
gotchaClosing the stream does not close the WebSocket; must close WebSocket separately.
fix
Call 'ws.close()' after stream ends or errors.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: WebSocketStream is not a constructor
Importing named export instead of default.
fix
Replace 'import { WebSocketStream }' with 'import WebSocketStream'.
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
Attempting to write to the stream after it has been closed.
fix
Check stream.writableEnded before writing, or listen for 'finish' event.
TypeError: ws is not a function
Passing a non-WebSocket object or unopened socket.
fix
Ensure the argument to WebSocketStream is a WebSocket instance with readyState === WebSocket.OPEN.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
22
OpenAI (training)
1
Resources
yws-stream — npm install yws-stream · libregistry