Gathering detailed insights and metrics for socket.io-pm2
Gathering detailed insights and metrics for socket.io-pm2
Gathering detailed insights and metrics for socket.io-pm2
Gathering detailed insights and metrics for socket.io-pm2
@socket.io/pm2
Production process manager for Node.JS applications with a built-in load balancer.
pm2-socket.io
PM2 Simple Socket.io Module
@grandeto/pm2-socket.io
Production process manager for Node.JS applications with a built-in load balancer.
lpcpanel

Adapter to enable broadcasting of events to a cluster of socket.io nodes running under PM2.
npm install socket.io-pm2
Typescript
Module System
Node Version
NPM Version
JavaScript (99.83%)
Makefile (0.17%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2 Stars
173 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Mar 17, 2023
Latest Version
1.0.0
Package Id
socket.io-pm2@1.0.0
Unpacked Size
26.49 kB
Size
5.93 kB
File Count
4
NPM Version
6.4.0
Node Version
11.7.0
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
5
4
1const io = require('socket.io')(3000); 2const pm2Adapter = require('socket.io-pm2'); 3io.adapter(pm2Adapter());
By running socket.io with the socket.io-pm2
adapter you can run
multiple socket.io instances in different processes on the same pm2 cluster that can
all broadcast and emit events to and from each other.
So any of the following commands:
1io.emit('hello', 'to all clients'); 2io.to('room42').emit('hello', "to all clients in 'room42' room"); 3 4io.on('connection', (socket) => { 5 socket.broadcast.emit('hello', 'to all clients except sender'); 6 socket.to('room42').emit('hello', "to all clients in 'room42' room except sender"); 7});
will properly be broadcast to the clients through PM2 IPC (inter-process communication).
If you need to emit events to socket.io instances from a non-socket.io process, you should use socket.io-emitter.
The following options are allowed:
key
: the name of the key to pub/sub events on as prefix (socket.io
)requestsTimeout
: optional, after this timeout the adapter will stop waiting from responses to request (5000ms
)The pm2 adapter instances expose the following properties
that a regular Adapter
does not
uid
prefix
requestsTimeout
Returns the list of client IDs connected to rooms
across all nodes. See Namespace#clients(fn:Function)
1io.of('/').adapter.clients((err, clients) => { 2 console.log(clients); // an array containing all connected socket ids 3}); 4 5io.of('/').adapter.clients(['room1', 'room2'], (err, clients) => { 6 console.log(clients); // an array containing socket ids in 'room1' and/or 'room2' 7}); 8 9// you can also use 10 11io.in('room3').clients((err, clients) => { 12 console.log(clients); // an array containing socket ids in 'room3' 13});
Returns the list of rooms the client with the given ID has joined (even on another node).
1io.of('/').adapter.clientRooms('<my-id>', (err, rooms) => { 2 if (err) { /* unknown id */ } 3 console.log(rooms); // an array containing every room a given id has joined. 4});
Returns the list of all rooms.
1io.of('/').adapter.allRooms((err, rooms) => { 2 console.log(rooms); // an array containing all rooms (accross every node) 3});
Makes the socket with the given id join the room. The callback will be called once the socket has joined the room, or with an err
argument if the socket was not found.
1io.of('/').adapter.remoteJoin('<my-id>', 'room1', (err) => { 2 if (err) { /* unknown id */ } 3 // success 4});
Makes the socket with the given id leave the room. The callback will be called once the socket has left the room, or with an err
argument if the socket was not found.
1io.of('/').adapter.remoteLeave('<my-id>', 'room1', (err) => { 2 if (err) { /* unknown id */ } 3 // success 4});
Makes the socket with the given id to get disconnected. If close
is set to true, it also closes the underlying socket. The callback will be called once the socket was disconnected, or with an err
argument if the socket was not found.
1io.of('/').adapter.remoteDisconnect('<my-id>', true, (err) => { 2 if (err) { /* unknown id */ } 3 // success 4});
Sends a request to every nodes, that will respond through the customHook
method.
1// on every node 2io.of('/').adapter.customHook = (data, cb) => { 3 cb('hello ' + data); 4} 5 6// then 7io.of('/').adapter.customRequest('john', function(err, replies){ 8 console.log(replies); // an array ['hello john', ...] with one element per node 9});
The socket.io-pm2
adapter broadcasts and receives messages on particularly named ipc topics.
For global broadcasts the channel name is:
prefix + '#' + namespace + '#'
In broadcasting to a single room the channel name is:
prefix + '#' + namespace + '#' + room + '#'
prefix
: The base channel name. Default value is socket.io
. Changed by setting opts.key
in adapter(opts)
constructornamespace
: See https://github.com/socketio/socket.io#namespace.room
: Used if targeting a specific room.A number of other libraries adopt this protocol including:
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/30 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 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
Reason
68 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
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