Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q7 of 15
Node.js - Child Processes
Identify the error in this code snippet:
const { fork } = require('child_process');
const child = fork('child.js');
child.on('message', msg => console.log(msg));
child.send();
Afork cannot be used with on('message') listener
Bsend() requires a message argument; missing here
Cchild.js must export a function to receive messages
Dchild process must be closed before sending messages
Step-by-Step Solution
Solution:
  1. Step 1: Check send method usage

    send() requires a message argument; calling send() without arguments causes an error.

  2. Step 2: Verify other options

    fork works with message listeners, child.js does not need to export a function, no need to close child before sending.

  3. Final Answer:

    send() requires a message argument; missing here -> Option B
  4. Quick Check:

    send argument required [OK]

Quick Trick: Always provide a message to send() [OK]
Common Mistakes:
  • Calling send() without arguments
  • Misunderstanding fork and message listener
  • Thinking child.js must export a function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes