0
0
Node.jsframework~5 mins

Worker thread vs child process in Node.js - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a Worker Thread in Node.js?
A Worker Thread is a way to run JavaScript code in parallel within the same Node.js process. It shares memory with the main thread but runs independently to perform CPU-intensive tasks without blocking the main event loop.
Click to reveal answer
beginner
What is a Child Process in Node.js?
A Child Process is a separate process created by the main Node.js process. It runs independently with its own memory and event loop, allowing you to run external programs or scripts without blocking the main process.
Click to reveal answer
intermediate
How do Worker Threads and Child Processes differ in memory usage?
Worker Threads share memory with the main thread using SharedArrayBuffer, which allows faster communication. Child Processes have separate memory spaces, so communication happens via inter-process messaging, which is slower.
Click to reveal answer
intermediate
When should you use a Worker Thread instead of a Child Process?
Use Worker Threads for CPU-heavy JavaScript tasks that need to run in parallel but share data efficiently. They are lighter and faster for tasks within Node.js. Use Child Processes when you need to run external programs or isolate tasks completely.
Click to reveal answer
advanced
What is a key limitation of Worker Threads compared to Child Processes?
Worker Threads run in the same process, so if a Worker Thread crashes, it can affect the main process. Child Processes are isolated, so a crash in a child does not crash the main process.
Click to reveal answer
Which Node.js feature runs JavaScript code in parallel within the same process?
AEvent Loop
BChild Process
CWorker Thread
DCallback Function
Which runs in a separate memory space and process?
AWorker Thread
BChild Process
CPromise
DAsync Function
Which is better for running external programs from Node.js?
AChild Process
BsetTimeout
CWorker Thread
DEvent Loop
Which communicates faster due to shared memory?
AWorker Thread
BFile System
CHTTP Request
DChild Process
What happens if a Worker Thread crashes?
AOnly the Worker Thread stops, main process continues
BNothing happens
CChild Process restarts automatically
DMain process crashes too
Explain the main differences between Worker Threads and Child Processes in Node.js.
Think about memory, process isolation, and use cases.
You got /5 concepts.
    When would you choose a Child Process over a Worker Thread in a Node.js application?
    Consider isolation and running non-JS code.
    You got /4 concepts.