Bird
0
0

Identify the error in this Node.js code using execFile:

medium📝 Debug Q14 of 15
Node.js - Child Processes
Identify the error in this Node.js code using execFile:
const { execFile } = require('child_process');
execFile('node', ['-v'], (err, stdout) => {
  if (err) throw err;
  console.log(stdout);
  console.error(stderr);
});
ACallback function should not have parameters
BWrong executable name 'node'
CMissing <code>stderr</code> parameter in callback
DexecFile cannot run 'node' command
Step-by-Step Solution
Solution:
  1. Step 1: Check callback parameters

    The callback for execFile should have three parameters: error, stdout, and stderr.
  2. Step 2: Identify missing parameter usage

    The code uses stderr but does not declare it in the callback parameters, causing a ReferenceError.
  3. Final Answer:

    Missing stderr parameter in callback -> Option C
  4. Quick Check:

    Callback must include stderr to use it = A [OK]
Quick Trick: Callback needs error, stdout, stderr parameters [OK]
Common Mistakes:
  • Forgetting stderr parameter in callback
  • Assuming execFile can't run node
  • Using wrong number of callback arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes