Bird
0
0

Which of the following is the correct way to import and use fork from the child_process module in Node.js?

easy📝 Syntax Q12 of 15
Node.js - Child Processes
Which of the following is the correct way to import and use fork from the child_process module in Node.js?
Aconst fork = require('child_process').fork();
Bconst { fork } = require('child_process');
Cimport fork from 'child_process';
Dconst fork = require('child_process').Fork;
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct import syntax for fork

    In Node.js CommonJS, fork is a named export from child_process, so we use destructuring: const { fork } = require('child_process');
  2. Step 2: Analyze each option

    const fork = require('child_process').fork(); calls fork() immediately, which is incorrect. import fork from 'child_process'; uses ES module syntax without proper setup. const fork = require('child_process').fork; assigns the function but misses destructuring. const { fork } = require('child_process'); is correct.
  3. Final Answer:

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

    Destructure fork from child_process = A [OK]
Quick Trick: Use curly braces to import fork: const { fork } = require(...) [OK]
Common Mistakes:
  • Calling fork() during import
  • Using ES module import without config
  • Not destructuring fork from module

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes