Gathering detailed insights and metrics for @httptoolkit/websocket-stream
Gathering detailed insights and metrics for @httptoolkit/websocket-stream
Gathering detailed insights and metrics for @httptoolkit/websocket-stream
Gathering detailed insights and metrics for @httptoolkit/websocket-stream
websockets with the node stream API
npm install @httptoolkit/websocket-stream
Typescript
Module System
Node Version
NPM Version
JavaScript (91.21%)
TypeScript (8.79%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
BSD-2-Clause License
3 Stars
234 Commits
2 Forks
2 Watchers
2 Branches
29 Contributors
Updated on May 09, 2023
Latest Version
6.0.1
Package Id
@httptoolkit/websocket-stream@6.0.1
Unpacked Size
29.00 kB
Size
8.62 kB
File Count
15
NPM Version
8.5.2
Node Version
14.18.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Part of HTTP Toolkit: powerful tools for building, testing & debugging HTTP(S)
Use HTML5 websockets using the Node Streams API.
This is a fork of the original websocket-stream (now unmaintained), for use in HTTP Toolkit. This fork:
This module works in Node or in Browsers that support WebSockets. You can use browserify to package this module for browser use.
1var websocket = require('@httptoolkit/websocket-stream') 2var ws = websocket('ws://echo.websocket.org') 3process.stdin.pipe(ws) 4ws.pipe(process.stdout)
In the example above ws
is a duplex stream. That means you can pipe output to anything that accepts streams. You can also pipe data into streams (such as a webcam feed or audio data).
The underlying WebSocket
instance is available as ws.socket
.
The available options differs depending on if you use this module in the browser or with node.js. Options can be passed in as the third or second argument - WebSocket(address, [protocols], [options])
.
options.browserBufferSize
How much to allow the socket.bufferedAmount to grow before starting to throttle writes. This option has no effect in node.js.
Default: 1024 * 512
(512KiB)
options.browserBufferTimeout
How long to wait before checking if the socket buffer has drained sufficently for another write. This option has no effect in node.js.
Default: 1000
(1 second)
options.objectMode
Send each chunk on its own, and do not try to pack them in a single websocket frame.
Default: false
options.binary
Always convert to Buffer
in Node.js before sending.
Forces options.objectMode
to false
.
Default: true
options.perMessageDeflate
We recommend disabling the per message deflate extension to achieve the best throughput.
Default: true
on the client, false
on the server.
Example:
1var websocket = require('@httptoolkit/websocket-stream') 2var ws = websocket('ws://realtimecats.com', { 3 perMessageDeflate: false 4})
Beware that this option is ignored by browser clients. To make sure that permessage-deflate is never used, disable it on the server.
When used in node.js see the ws.WebSocket documentation
Using the ws
module you can make a websocket server and use this module to get websocket streams on the server:
1var websocket = require('@httptoolkit/websocket-stream') 2var wss = websocket.createServer({server: someHTTPServer}, handle) 3 4function handle(stream, request) { 5 // `request` is the upgrade request sent by the client. 6 fs.createReadStream('bigdata.json').pipe(stream) 7}
We recommend disabling the per message deflate extension to achieve the best throughput:
1var websocket = require('@httptoolkit/websocket-stream') 2var wss = websocket.createServer({ 3 perMessageDeflate: false, 4 server: someHTTPServer 5}, handle) 6 7function handle(stream) { 8 fs.createReadStream('bigdata.json').pipe(stream) 9}
You can even use it on express.js with the express-ws library:
1const express = require('express'); 2const expressWebSocket = require('express-ws'); 3const websocketStream = require('websocket-stream/stream'); 4const app = express(); 5 6// extend express app with app.ws() 7expressWebSocket(app, null, { 8 // ws options here 9 perMessageDeflate: false, 10}); 11 12app.ws('/bigdata.json', function(ws, req) { 13 // convert ws instance to stream 14 const stream = websocketStream(ws, { 15 // websocket-stream options here 16 binary: true, 17 }); 18 19 fs.createReadStream('bigdata.json').pipe(stream); 20}); 21 22app.listen(3000);
npm test
First start the echo server by running node test-server.js
Then run npm start
and open localhost:9966
in your browser and open the Dev Tools console to see test output.
BSD LICENSE
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More