Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
If you have 2 independent NodeJS processes running and want them to communicate, this can be done reliably using a npm package: node-ipc
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();
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");
});
});
@heisian

This comment has been minimized.

Copy link

@heisian heisian commented Jul 28, 2017

You have a typo:

 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");
  });
});

Both occurrences of jest-observer should be a-unique-process-name1.

@quangogster

This comment has been minimized.

Copy link

@quangogster quangogster commented Oct 25, 2018

@heisian thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment