Bird
0
0

Which of the following is the correct way to create a child process in Node.js?

easy📝 Syntax Q12 of 15
Node.js - Child Processes
Which of the following is the correct way to create a child process in Node.js?
Aconst child = require('child_process').fork('script.js');
Bconst child = require('child_process').start('script.js');
Cconst child = require('child_process').run('script.js');
Dconst child = require('child_process').execute('script.js');
Step-by-Step Solution
Solution:
  1. Step 1: Recall Node.js child process methods

    The 'child_process' module has methods like fork(), spawn(), exec(), but not start() or run().
  2. Step 2: Identify correct method for creating a child process running a script

    fork() is used to create a new Node.js process running a script file.
  3. Final Answer:

    const child = require('child_process').fork('script.js'); -> Option A
  4. Quick Check:

    fork() creates child process = A [OK]
Quick Trick: Use fork() to create child Node.js processes [OK]
Common Mistakes:
  • Using non-existent methods like start() or run()
  • Confusing exec() with fork() for script processes
  • Forgetting to require 'child_process' module

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes