Fork() is used to spawn a new Node.js process. It invokes a specific module with an IPC communication channel, thus enabling the sending of messages between a parent and child.

BY Best Interview Question ON 21 Feb 2021


const { fork } = require('child_process');

const forked = fork('child.js');

forked.on('message', (msg) => {
     console.log('Message from child', msg);

forked.send({ hello: 'world' });

Suggest An Answer