0
0
Node.jsframework~10 mins

IPC communication between processes in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a child process using Node.js built-in module.

Node.js
const { [1] } = require('child_process');
const child = [1].fork('child.js');
Drag options to blanks, or click blank then click option'
Aspawn
Bfork
Cexec
DexecFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'spawn' instead of 'fork' which does not set up IPC automatically.
Using 'exec' which runs a shell command but doesn't create a Node.js child process.
2fill in blank
medium

Complete the code to send a message from the parent process to the child process.

Node.js
child.[1]({ text: 'Hello child' });
Drag options to blanks, or click blank then click option'
Asend
BpostMessage
Cwrite
Demit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'emit' which is for event emitters but not for IPC message sending.
Using 'write' which is for streams, not IPC messages.
3fill in blank
hard

Fix the error in the child process code to receive messages from the parent.

Node.js
process.[1]('message', (msg) => {
  console.log('Received:', msg);
});
Drag options to blanks, or click blank then click option'
Alisten
BaddListener
Con
DonMessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'onMessage' which is not a valid method.
Using 'listen' which is not an event listener method.
4fill in blank
hard

Fill both blanks to send a message from child to parent and listen in parent.

Node.js
// In child process
process.[1]({ reply: 'Hi parent' });

// In parent process
child.[2]('message', (msg) => {
  console.log('From child:', msg);
});
Drag options to blanks, or click blank then click option'
Asend
Bon
Cemit
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'emit' instead of 'send' for IPC messages.
Using 'write' which is for streams, not IPC.
5fill in blank
hard

Fill all three blanks to create a simple IPC communication where parent sends, child replies, and parent listens.

Node.js
// Parent process
const { [1] } = require('child_process');
const child = [1].fork('child.js');
child.[2]({ greeting: 'Hello child' });
child.[3]('message', (msg) => {
  console.log('Child says:', msg);
});
Drag options to blanks, or click blank then click option'
Afork
Bsend
Con
Dspawn
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'spawn' instead of 'fork' which does not set up IPC.
Using 'emit' instead of 'send' for sending messages.