Bird
0
0

How do you correctly import the exec function from the child_process module in Node.js?

easy📝 Syntax Q3 of 15
Node.js - Child Processes
How do you correctly import the exec function from the child_process module in Node.js?
Aconst { exec } = require('child_process');
Bimport exec from 'child_process';
Cconst exec = require('exec');
Dconst exec = import('child_process').exec;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct import syntax

    Node.js uses CommonJS require syntax for built-in modules.
  2. Step 2: Correct destructuring

    The exec function is a named export from child_process, so destructuring is needed.
  3. Final Answer:

    const { exec } = require('child_process'); -> Option A
  4. Quick Check:

    Use require with destructuring for exec [OK]
Quick Trick: Use require with destructuring for exec [OK]
Common Mistakes:
  • Using ES6 import syntax without transpilation
  • Requiring a non-existent 'exec' module
  • Incorrect destructuring or assignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes