Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-pm2-events

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-pm2-events

PM2 decentralized instances eventbus with web socket addon

  • 1.0.2
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by83.33%
Maintainers
1
Weekly downloads
 
Created
Source

Data exchange between instances of pm2 services located on decentralized servers (virtual machines), etc.

The usual mechanism embedded in the process notification

process.on('message', async function (packet){
    // do something with packet.data
}

does not include distributed virtual instances, but locally causes a pm2 instance crash under heavy load.

An example of data exchange between different instances (decentralized or not - it doesn't matter)

const Events = require('node-pm2-events');

// pm2 some instances test
const redisExternalSenderServer = new Events.Redis('some-server-1', {...Config.redis, debug: true});
const redisReceiver = new Events.Redis('other-server-2', {...Config.redis, debug: true});

redisReceiver.onMessage(async (channel, message) => {
    console.log(redisReceiver.originatorId, 'receive message', channel, message)
}).subscribe(channelName);

let count = 0;
const timer = setInterval(() => {
    const v = {action: 'contract', obj: {_d: 2}, _id: String(Date.now()).hash()}
    redisExternalSenderServer.publish(channelName, v);
    if (count++ > 100) process.exit();
}, 10);

Usage example with websocket

const Events = require('node-pm2-events');

const channelName = 'AweSome Channel Or Event Name';
const pm2 = new Events.Pm2({...Config.redis, debug: true});
// Listen to all external events and broadcast them locally 
// to all connected clients via websocket
pm2.addEventListener(channelName);

// Sending a local event anywhere in the project.
// Will be caught locally and passed to other pm2 instances and attempt 
// to pass to all connected websocket clients.
pm2.dispatch(channelName, {awesome: 'something'});

Redis is used for exchange: ioredis

Keywords

FAQs

Package last updated on 12 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc