Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to communicate between nodejs applications

// article on medium about this
// below are 2 independent running nodejs applications, which communicate using IPC

// process1.js
// This Process starts the pub-sub server, which other processes can connect to.
const ipc = require('node-ipc');

ipc.config.id = 'a-unique-process-name1';
ipc.config.retry = 1500;
ipc.config.silent = true;
ipc.serve(() => ipc.server.on('a-unique-message-name', message => {
  console.log(message);
}));
ipc.server.start();

// process2.js
const ipc = require('node-ipc');

ipc.config.id = 'a-unique-process-name2';
ipc.config.retry = 1500;
ipc.config.silent = true;
ipc.connectTo('a-unique-process-name1', () => {
  ipc.of['jest-observer'].on('connect', () => {
    ipc.of['jest-observer'].emit('a-unique-message-name', "The message we send");
  });
});

Source by medium.com #
 
PREVIOUS NEXT
Tagged: #communicate #nodejs #applications
ADD COMMENT
Topic
Name
3+3 =