Recall & Review
beginner
What does the
fork method in Node.js do?It creates a new child process that runs a separate Node.js script. This allows running code in parallel without blocking the main program.
Click to reveal answer
beginner
How do parent and child processes communicate when using
fork?They communicate via a built-in IPC channel. Parent uses
child.send() and child.on('message'); child uses process.send() and process.on('message').Click to reveal answer
intermediate
What is a common use case for using
fork in Node.js?To run CPU-heavy tasks or separate workloads in parallel without blocking the main event loop, improving performance and responsiveness.
Click to reveal answer
beginner
Which module do you need to import to use <code>fork</code> in Node.js?You need to import the <code>child_process</code> module using <code>const { fork } = require('child_process');</code>.Click to reveal answer
intermediate
What happens if the child process created by
fork exits unexpectedly?The parent process can listen for the
'exit' or 'close' events on the child process object to handle cleanup or restart the child.Click to reveal answer
What does
fork return in Node.js?✗ Incorrect
fork returns a ChildProcess object that represents the new child process.
Which method is used to send a message from the parent to the child process?
✗ Incorrect
The parent uses child.send() to send messages to the child process.
How does the child process listen for messages from the parent?
✗ Incorrect
The child listens on its own process object for 'message' events.
Which module must be imported to use
fork?✗ Incorrect
fork is part of the child_process module.
What is a key benefit of using
fork over exec or spawn?✗ Incorrect
fork creates a Node.js child process with a communication channel, unlike exec or spawn.
Explain how to create a child process using
fork and how the parent and child communicate.Think about the steps to start and talk between processes.
You got /5 concepts.
Describe a scenario where using
fork improves a Node.js application's performance.Consider tasks that slow down the main program.
You got /5 concepts.