Bird
0
0

Given this code snippet, what will be logged when run as a master process?

medium📝 component behavior Q4 of 15
Node.js - Cluster Module
Given this code snippet, what will be logged when run as a master process?
const cluster = require('cluster');
if (cluster.isMaster) {
  console.log('Master process running');
} else {
  console.log('Worker process running');
}
AError: cluster is not defined
BMaster process running
CNo output
DWorker process running
Step-by-Step Solution
Solution:
  1. Step 1: Check the condition for master process

    The code checks if cluster.isMaster is true, then logs 'Master process running'.
  2. Step 2: Since running as master, else block is skipped

    Only the master message is logged.
  3. Final Answer:

    The output is 'Master process running' -> Option B
  4. Quick Check:

    Master process logs master message [OK]
Quick Trick: cluster.isMaster true means master code runs [OK]
Common Mistakes:
  • Confusing master and worker output
  • Expecting error without require
  • Thinking both messages print

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes