Complete the code to create a child process using Node.js.
const { spawn } = require('[1]');
const child = spawn('ls', ['-lh', '/usr']);Node.js uses the child_process module to create child processes.
Complete the code to listen for data from the child process's stdout.
child.stdout.on('[1]', (data) => { console.log(`Output: ${data}`); });
The data event is emitted when the child process sends output.
Fix the error in the code to correctly handle child process exit.
child.on('[1]', (code) => { console.log(`Child exited with code ${code}`); });
The exit event is emitted when the child process ends.
Fill both blanks to create a child process that runs a script and handle errors.
const child = require('child_process').[1]('node', ['script.js']); child.on('[2]', (err) => { if (err) console.error('Error:', err); });
spawn starts a new process, and error event handles errors.
Fill all three blanks to create a child process, listen for output, and handle exit.
const { [1] } = require('child_process');
const child = [2]('ls', ['-la']);
child.on('[3]', (code) => {
console.log(`Process ended with code ${code}`);
});Destructure spawn from the child_process module, use spawn to create the process, and listen for exit event.
