Complete the code to import the correct method to create a child process.
const { [1] } = require('child_process');spawn or exec which are for other process types.The fork method is used to create a new Node.js process that can communicate with the parent process.
Complete the code to fork a child process running the script 'worker.js'.
const child = fork('[1]');
The fork method takes the path to the JavaScript file to run in the child process. Here, it is worker.js.
Fix the error in sending a message from the parent to the child process.
child.[1]({ type: 'start' });
emit which is for events, not IPC messages.The send method is used to send messages to a child process created with fork.
Fill both blanks to listen for messages from the child process and log them.
child.on('[1]', ([2]) => { console.log('Message from child:', [2]); });
send or data.The event to listen for messages is message. The callback receives the message, here named msg.
Fill all three blanks to create a child process, send a message, and handle its exit.
const child = [1]('task.js'); child.[2]({ action: 'run' }); child.on('[3]', () => { console.log('Child process exited'); });
spawn instead of fork.emit instead of send.close instead of exit.Use fork to create the child, send to communicate, and listen for the exit event to know when it ends.