0
0
Node.jsframework~10 mins

Why process management matters in Node.js - Test Your Understanding

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

Complete the code to start a child process that runs a Node.js script.

Node.js
const { spawn } = require('child_process');
const child = spawn('node', ['[1]']);
Drag options to blanks, or click blank then click option'
Aserver.json
Bindex.html
Cstyle.css
Dapp.js
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-JavaScript file like HTML or CSS as the script to run.
2fill in blank
medium

Complete the code to listen for the 'exit' event of the child process.

Node.js
child.on('[1]', (code) => {
  console.log(`Child exited with code ${code}`);
});
Drag options to blanks, or click blank then click option'
Astart
Berror
Cexit
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' or 'close' instead of 'exit' event.
3fill in blank
hard

Fix the error in the code to correctly kill the child process.

Node.js
child.[1]('SIGTERM');
Drag options to blanks, or click blank then click option'
Astop
Bkill
Cterminate
Dend
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'stop' or 'terminate'.
4fill in blank
hard

Fill both blanks to spawn a child process with arguments and handle errors.

Node.js
const child = spawn('node', ['[1]']);
child.on('[2]', (err) => {
  console.error('Failed to start child process:', err);
});
Drag options to blanks, or click blank then click option'
Ascript.js
Berror
Cexit
Dapp.js
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exit' event to catch errors instead of 'error' event.
5fill in blank
hard

Fill all three blanks to spawn a child process, listen for exit, and send a kill signal.

Node.js
const child = spawn('[1]', ['[2]']);
child.on('[3]', (code) => {
  console.log(`Process exited with code ${code}`);
  child.kill('SIGINT');
});
Drag options to blanks, or click blank then click option'
Anode
Bserver.js
Cexit
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'error' event instead of 'exit' to detect process end.