0
0
Node.jsframework~10 mins

fork for Node.js child 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 import the correct method to create a child process.

Node.js
const { [1] } = require('child_process');
Drag options to blanks, or click blank then click option'
AexecFile
Bexec
Cfork
Dspawn
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing spawn or exec which are for other process types.
2fill in blank
medium

Complete the code to fork a child process running the script 'worker.js'.

Node.js
const child = fork('[1]');
Drag options to blanks, or click blank then click option'
A'worker.js'
B'server.js'
C'child.js'
D'index.js'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong file name that does not exist or is not intended.
3fill in blank
hard

Fix the error in sending a message from the parent to the child process.

Node.js
child.[1]({ type: 'start' });
Drag options to blanks, or click blank then click option'
Aemit
BpostMessage
Cwrite
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using emit which is for events, not IPC messages.
4fill in blank
hard

Fill both blanks to listen for messages from the child process and log them.

Node.js
child.on('[1]', ([2]) => {
  console.log('Message from child:', [2]);
});
Drag options to blanks, or click blank then click option'
Amessage
Bmsg
Cdata
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong event names like send or data.
5fill in blank
hard

Fill all three blanks to create a child process, send a message, and handle its exit.

Node.js
const child = [1]('task.js');
child.[2]({ action: 'run' });
child.on('[3]', () => {
  console.log('Child process exited');
});
Drag options to blanks, or click blank then click option'
Afork
Bsend
Cexit
Dspawn
Attempts:
3 left
💡 Hint
Common Mistakes
Using spawn instead of fork.
Using emit instead of send.
Listening for wrong events like close instead of exit.