Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does IPC stand for in Node.js?
IPC stands for Inter-Process Communication. It allows different processes to talk and share data with each other.
Click to reveal answer
beginner
Name two common ways Node.js processes communicate using IPC.
1. Using child process's built-in messaging with process.send() and process.on('message'). 2. Using sockets or named pipes for more complex communication.
Click to reveal answer
beginner
How do you send a message from a parent process to a child process in Node.js?
Use child.send(message) where child is the child process object created by fork().
Click to reveal answer
beginner
What event do you listen to in a child process to receive messages from the parent?
Listen to the 'message' event on process inside the child process, like process.on('message', (msg) => { ... }).
Click to reveal answer
beginner
Why is IPC useful in Node.js applications?
IPC helps split work into multiple processes to improve performance and reliability. Processes can share data and coordinate tasks without blocking each other.
Click to reveal answer
Which Node.js method sends a message from a child process to its parent?
Aprocess.emit()
Bprocess.send()
Cchild.send()
Dchild.emit()
✗ Incorrect
In a child process, use process.send() to send messages to the parent.
What event should a parent process listen to receive messages from a child?
A'message' event on process object
B'data' event on process object
C'send' event on child process
D'message' event on child process object
✗ Incorrect
The parent listens to the 'message' event on the child process object to get messages.
Which Node.js module is commonly used to create child processes for IPC?
Afs
Bhttp
Cchild_process
Devents
✗ Incorrect
The child_process module provides methods like fork() to create child processes.
What does the fork() method do in Node.js?
ACreates a new child process with IPC channel
BCreates a new thread
CStarts a web server
DReads a file asynchronously
✗ Incorrect
fork() creates a child process with a communication channel for IPC.
Why might you use IPC instead of sharing variables directly between processes?
ABecause processes do not share memory
BBecause IPC is faster than variables
CBecause variables are deprecated
DBecause IPC uses global variables
✗ Incorrect
Processes have separate memory, so IPC is needed to exchange data safely.
Explain how a parent and child process communicate using IPC in Node.js.
Think about how messages are sent and received between processes.
You got /5 concepts.
Describe why IPC is important when working with multiple Node.js processes.
Consider what happens when processes run independently but need to work together.
You got /5 concepts.
Practice
(1/5)
1. What does IPC stand for in Node.js context and why is it useful?
easy
A. Internet Protocol Communication; it handles network requests.
B. Internal Process Control; it manages process memory usage.
C. Input-Process-Cache; it speeds up data processing.
D. Inter-Process Communication; it allows processes to exchange messages.
Solution
Step 1: Understand IPC meaning and its use in Node.js
IPC means Inter-Process Communication, which is about processes exchanging data. In Node.js, IPC lets parent and child processes send messages to coordinate work.
Final Answer:
Inter-Process Communication; it allows processes to exchange messages. -> Option D
Quick Check:
IPC = Inter-Process Communication [OK]
Hint: IPC means processes talking to each other [OK]
Common Mistakes:
Confusing IPC with network protocols
Thinking IPC manages memory or caching
Mixing up IPC with internal process controls
2. Which Node.js method is used to create a child process that supports IPC?
easy
A. child_process.spawn()
B. child_process.exec()
C. child_process.fork()
D. child_process.execFile()
Solution
Step 1: Review child process methods and identify the one enabling IPC
spawn(), exec(), execFile() create processes but don't enable IPC by default. fork() creates a child process with an IPC channel for message passing.
Final Answer:
child_process.fork() -> Option C
Quick Check:
fork() creates IPC-enabled child process [OK]
Hint: Use fork() for IPC between parent and child [OK]
A. Parent sends message before child process is ready to receive.
B. Child process sends message before 'message' event listener is set.
C. Child process calls process.send() before parent listens.
D. No error; code works correctly.
Solution
Step 1: Analyze message timing and understand child readiness
Parent sends 'Start' immediately after fork; child may not be ready yet. Child sends 'Ready' immediately but parent may miss it if not listening yet.
Final Answer:
Parent sends message before child process is ready to receive. -> Option A
Quick Check:
Parent must wait for child's 'Ready' before sending [OK]
Hint: Wait for child's ready message before sending [OK]
Common Mistakes:
Assuming child is ready immediately after fork
Ignoring asynchronous nature of IPC
Thinking process.send() order causes error
5. You want to create a Node.js parent process that forks two child processes. Each child sends a number to the parent, and the parent must send back the sum of both numbers to each child. Which approach correctly implements this IPC communication?
hard
A. Parent listens to both children messages, sums numbers, then sends sum to each child using child.send(sum).
B. Each child sends its number to the other child directly using process.send().
C. Parent forks children but does not set up message listeners; children communicate directly.
D. Children send numbers to parent, but parent sends sum only to the first child.
Solution
Step 1: Understand parent-child communication and message handling
Children cannot send messages directly to each other; parent mediates IPC. Parent listens to messages from both children, calculates sum, then sends sum back to each child.
Final Answer:
Parent listens to both children messages, sums numbers, then sends sum to each child using child.send(sum). -> Option A
Quick Check:
Parent mediates and broadcasts sum to children [OK]
Hint: Parent must mediate messages and send sum to all children [OK]
Common Mistakes:
Trying to send messages directly between children
Not sending sum to both children
Not listening to both children's messages in parent