Bird
0
0

What is wrong with this cluster code snippet?

medium📝 Debug Q14 of 15
Node.js - Cluster Module
What is wrong with this cluster code snippet?
const cluster = require('cluster');
if (cluster.isPrimary) {
  cluster.fork();
} else {
  console.log('Worker running');
}
Acluster.isPrimary is deprecated, should use isMaster
BNo call to cluster.fork in the worker process
CMissing server code inside worker
DNo error, code works fine
Step-by-Step Solution
Solution:
  1. Step 1: Check cluster usage

    The primary forks one worker, which only logs a message but does not start a server.
  2. Step 2: Identify missing functionality

    Without server code, the worker does not handle requests, so the cluster setup is incomplete.
  3. Final Answer:

    Missing server code inside worker -> Option C
  4. Quick Check:

    Worker must run server code to handle requests [OK]
Quick Trick: Workers need server code to handle requests [OK]
Common Mistakes:
  • Confusing isPrimary with deprecated isMaster
  • Expecting cluster.fork in worker process
  • Assuming code runs without server in worker

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes