M
M
Maxla932016-10-10 19:30:49
Node.js
Maxla93, 2016-10-10 19:30:49

How to share data between 3 running processes in Node.js?

Created a cluster and divided into 3 processes.
1 - main
2 and 3 (the so-called bots that must exchange information with the main process).
Could you tell me how to implement the exchange of information in real time?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Taratin, 2016-10-10
@Taraflex

https://github.com/RIAEvangelist/node-ipc
https://github.com/sidorares/node-dbus

S
s2dent, 2016-10-20
@s2dent

There are plenty of options and it is not necessary to use third-party modules, you can work with sockets (this is how the node-ipc, node-dbus and many other modules designed for these purposes work) through the built-in "net" module.
https://nodejs.org/api/net.html
Or, alternatively, launch child processes from the main process and communicate with them like this.
https://nodejs.org/api/child_process.html (child_process.fork())

const bot1= require('child_process').fork('./bot1.js');
bot1.send({param: value});
bot1.on('message', function (message) {
//...
});

In general, there are plenty of options, dnode , messenger.js , etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question