Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Node.js - Child Processes
Identify the error in this code snippet:
const { execFile } = require('child_process');
execFile('ls', ['-l'], (error, stdout) => {
  if (error) throw error;
  console.log(stderr);
});
ACallback parameters are in wrong order
Bstderr is undefined in the callback
CexecFile does not accept arguments array
DMissing import of execFile
Step-by-Step Solution
Solution:
  1. Step 1: Check callback parameters

    The callback receives (error, stdout, stderr). This code only declares (error, stdout), so stderr is undefined.
  2. Step 2: Identify usage of undefined variable

    The code tries to log stderr which is not declared, causing a ReferenceError.
  3. Final Answer:

    stderr is undefined in the callback -> Option B
  4. Quick Check:

    Missing stderr param causes undefined error [OK]
Quick Trick: Callback must declare stderr to use it [OK]
Common Mistakes:
  • Forgetting stderr parameter in callback
  • Assuming execFile does not take args array
  • Ignoring import statement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes