Bird
0
0

Identify the error in this Node.js cluster code snippet:

medium📝 Debug Q6 of 15
Node.js - Cluster Module
Identify the error in this Node.js cluster code snippet:
const cluster = require('cluster');
if (cluster.isMaster) {
  cluster.fork();
} else {
  console.log('Worker running');
}
AMissing call to cluster.setupMaster().
BUsing deprecated 'isMaster' instead of 'isPrimary'.
Ccluster.fork() must be called outside the if block.
DNo error; code runs correctly.
Step-by-Step Solution
Solution:
  1. Step 1: Check cluster API usage

    Recent Node.js versions replaced 'isMaster' with 'isPrimary'.
  2. Step 2: Identify deprecated property usage

    Using 'cluster.isMaster' causes warnings or errors in modern Node.js.
  3. Final Answer:

    Using deprecated 'isMaster' instead of 'isPrimary'. -> Option B
  4. Quick Check:

    Use isPrimary, not isMaster [OK]
Quick Trick: Use cluster.isPrimary for master check in Node.js 16+ [OK]
Common Mistakes:
  • Ignoring deprecation warnings
  • Thinking cluster.fork() placement is wrong
  • Assuming setupMaster() is mandatory here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes