Complete the code to start a child process that runs a Node.js script.
const { spawn } = require('child_process');
const child = spawn('node', ['[1]']);The spawn function starts a new process running the specified script. Here, app.js is the Node.js script to run.
Complete the code to listen for the 'exit' event of the child process.
child.on('[1]', (code) => { console.log(`Child exited with code ${code}`); });
The 'exit' event fires when the child process finishes. Listening to it helps know when the process ends.
Fix the error in the code to correctly kill the child process.
child.[1]('SIGTERM');
The kill method sends a signal to terminate the child process. Other options are not valid methods.
Fill both blanks to spawn a child process with arguments and handle errors.
const child = spawn('node', ['[1]']); child.on('[2]', (err) => { console.error('Failed to start child process:', err); });
The first blank is the script to run. The second blank is the 'error' event to catch startup failures.
Fill all three blanks to spawn a child process, listen for exit, and send a kill signal.
const child = spawn('[1]', ['[2]']); child.on('[3]', (code) => { console.log(`Process exited with code ${code}`); child.kill('SIGINT'); });
The first blank is the command 'node'. The second is the script 'server.js'. The third is the 'exit' event to detect process end.