Complete the code to import the cluster module in Node.js.
const cluster = require('[1]');
The cluster module is imported using require('cluster') to create master and worker processes.
Complete the code to check if the current process is the master process.
if (cluster.[1]) { console.log('This is the master process'); }
The property cluster.isPrimary is true if the current process is the primary (master) process in recent Node.js versions.
Fix the error in the code to fork a worker process.
if (cluster.isPrimary) { cluster.[1](); }
The method cluster.fork() creates a new worker process.
Fill both blanks to listen for 'message' events in the master and worker processes.
if (cluster.isPrimary) { const worker = cluster.fork(); worker.[1]('message', (msg) => { console.log('Master received:', msg); }); } else { process.[2]('message', (msg) => { console.log('Worker received:', msg); }); }
Both the worker and master listen for messages using the on method.
Fill all three blanks to send a message from the master to the worker and reply back.
if (cluster.isPrimary) { const worker = cluster.fork(); worker.[1]({ cmd: 'start' }); worker.[2]('message', (msg) => { console.log('Master got reply:', msg); }); } else { process.[3]('message', (msg) => { if (msg.cmd === 'start') { process.send({ reply: 'done' }); } }); }
The master sends a message with send, listens with on, and the worker listens with on.