Skip to content

Instantly share code, notes, and snippets.

@csantos42
Last active September 9, 2018 17:48
Child Process Example
// parent.js
const cp = require('child_process');
const CHILD_PATH = `${__dirname}/child.js`;
const queue = [1, 2, 3, 4, 5];
queue.forEach((num) => {
const child = cp.fork(CHILD_PATH);
child.on('message', (msg) => console.log(msg));
child.send(num);
});
// child.js
process.on('message', (num) => {
process.send(num + 1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment