Skip to content

Instantly share code, notes, and snippets.

@Paratron
Created February 4, 2020 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Paratron/488d4e0972bd8c99b2cd9a04903362cd to your computer and use it in GitHub Desktop.
Save Paratron/488d4e0972bd8c99b2cd9a04903362cd to your computer and use it in GitHub Desktop.
Node cross process communication
// One Process needs to be the host
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('eventName', message => {
console.log(message);
}));
ipc.server.start();
//Now other processes can send messages to it
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('eventName', "Content Message");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment