Bird
0
0

What is the main way to send data to a worker thread in Node.js when you create it?

easy📝 Conceptual Q1 of 15
Node.js - Worker Threads
What is the main way to send data to a worker thread in Node.js when you create it?
AUse the workerData option in the Worker constructor
BSend data via process.env variables
CUse global variables accessible by the worker
DPass data through command line arguments
Step-by-Step Solution
Solution:
  1. Step 1: Understand worker thread creation

    When creating a worker thread, you can pass initial data using the workerData option in the Worker constructor.
  2. Step 2: Compare other methods

    Environment variables and command line arguments are not standard ways to pass data directly to workers. Global variables are not shared between threads.
  3. Final Answer:

    Use the workerData option in the Worker constructor -> Option A
  4. Quick Check:

    Passing data to workers = workerData option [OK]
Quick Trick: Pass initial data via workerData option in Worker constructor [OK]
Common Mistakes:
  • Trying to use global variables for data sharing
  • Using environment variables for worker data
  • Passing data only after worker creation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes