Skip to content

Instantly share code, notes, and snippets.

@zeteticl
Forked from ndelangen/child.js
Created January 19, 2021 08:35
Show Gist options
  • Save zeteticl/1e40587ff6f959483a38db8c09eddb88 to your computer and use it in GitHub Desktop.
Save zeteticl/1e40587ff6f959483a38db8c09eddb88 to your computer and use it in GitHub Desktop.
NodeJS child_process communication (IPC) example
if (process.send) {
process.send("Hello");
}
process.on('message', message => {
console.log('message from parent:', message);
});
const fork = require('child_process').fork;
const program = path.resolve('child.js');
const parameters = [];
const options = {
stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ]
};
const child = fork(program, parameters, options);
child.on('message', message => {
console.log('message from child:', message);
child.send('Hi');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment