Gathering detailed insights and metrics for koa-websocket
Gathering detailed insights and metrics for koa-websocket
Gathering detailed insights and metrics for koa-websocket
Gathering detailed insights and metrics for koa-websocket
Light wrapper around Koa providing a websocket middleware handler that is koa-route compatible.
npm install koa-websocket
Typescript
Module System
Node Version
NPM Version
89.1
Supply Chain
98.9
Quality
75.4
Maintenance
100
Vulnerability
100
License
JavaScript (98.95%)
Dockerfile (1.05%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
260 Stars
134 Commits
38 Forks
3 Watchers
11 Branches
8 Contributors
Updated on Mar 12, 2025
Latest Version
7.0.0
Package Id
koa-websocket@7.0.0
Unpacked Size
18.11 kB
Size
8.51 kB
File Count
16
NPM Version
8.5.0
Node Version
16.14.2
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
Koa v2 is now the default. For Koa v1 support install with koa-websocket@2 and see the
legacy
branch.
Supports ws://
and wss://
npm install koa-websocket
1const Koa = require('koa'), 2 route = require('koa-route'), 3 websockify = require('koa-websocket'); 4 5const app = websockify(new Koa()); 6 7// Regular middleware 8// Note it's app.ws.use and not app.use 9app.ws.use(function(ctx, next) { 10 // return `next` to pass the context (ctx) on to the next ws middleware 11 return next(ctx); 12}); 13 14// Using routes 15app.ws.use(route.all('/test/:id', function (ctx) { 16 // `ctx` is the regular koa context created from the `ws` onConnection `socket.upgradeReq` object. 17 // the websocket is added to the context on `ctx.websocket`. 18 ctx.websocket.send('Hello World'); 19 ctx.websocket.on('message', function(message) { 20 // do something with the message from client 21 console.log(message); 22 }); 23})); 24 25app.listen(3000);
Example with Let's Encrypt (the Greenlock package):
1const Koa = require('koa'); 2const greenlock = require('greenlock-express'); 3const websockify = require('koa-websocket'); 4 5const le = greenlock.create({ 6 // all your sweet Let's Encrypt options here 7}); 8 9// the magic happens right here 10const app = websockify(new Koa(), wsOptions, le.httpsOptions); 11 12app.ws.use((ctx) => { 13 // the websocket is added to the context as `ctx.websocket`. 14 ctx.websocket.on('message', function(message) { 15 // do something 16 }); 17}); 18 19app.listen(3000);
With custom websocket options.
1const Koa = require('koa'), 2 route = require('koa-route'), 3 websockify = require('koa-websocket'); 4 5const wsOptions = {}; 6const app = websockify(new Koa(), wsOptions); 7 8app.ws.use(route.all('/', (ctx) => { 9 // the websocket is added to the context as `ctx.websocket`. 10 ctx.websocket.on('message', function(message) { 11 // print message from the client 12 console.log(message); 13 }); 14})); 15 16app.listen(3000);
The WebSocket options object just get passed right through to the new WebSocketServer(options)
call.
The optional HTTPS options object gets passed right into https.createServer(options)
. If the HTTPS options are
passed in, koa-websocket will use the built-in Node HTTPS server to provide support for the wss://
protocol.
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 0/6 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
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