Bird
0
0

Identify the error in this cluster setup code:

medium📝 Debug Q6 of 15
Node.js - Cluster Module
Identify the error in this cluster setup code:
const cluster = require('cluster');
if (cluster.isWorker) {
  console.log('Master process running');
} else {
  cluster.fork();
}
AUsing cluster.isWorker instead of cluster.isMaster to check master
BCalling cluster.fork() inside the worker process
CMissing event listener for worker exit
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check condition logic

    The code uses cluster.isWorker to detect master, which is incorrect; master should be checked with cluster.isMaster.
  2. Step 2: Confirm fork usage

    Fork is called in the else block, which runs in master, so no fork inside worker.
  3. Final Answer:

    Using cluster.isWorker instead of cluster.isMaster to check master -> Option A
  4. Quick Check:

    Use cluster.isMaster to detect master = B [OK]
Quick Trick: Use cluster.isMaster to detect master process [OK]
Common Mistakes:
  • Confusing isWorker and isMaster
  • Calling fork inside worker
  • Ignoring event listeners (not error here)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes