Complete the code to import the spawn function from the child_process module.
const { [1] } = require('child_process');The spawn function is imported from the child_process module to create streaming child processes.
Complete the code to spawn a child process that runs the 'ls' command.
const ls = spawn('[1]');
The ls command lists directory contents on Unix-like systems and is used here with spawn.
Fix the error in the code to correctly handle the data event from the child process stdout stream.
ls.stdout.on('[1]', (data) => { console.log(`Output: ${data}`); });
The data event is emitted when the child process sends output data on stdout.
Fill both blanks to spawn a process running 'node' with arguments ['-v'] and handle its exit event.
const proc = spawn('[1]', ['[2]']); proc.on('exit', (code) => { console.log(`Process exited with code ${code}`); });
The node command runs Node.js, and -v prints its version. The exit event tells when the process finishes.
Fill all three blanks to create a child process that runs 'grep' to filter 'error' from input, and handle its stdout data event.
const grep = spawn('[1]', ['[2]']); grep.stdout.on('[3]', (data) => { console.log(`Filtered output: ${data}`); });
grep filters input lines matching 'error'. The data event reads the filtered output stream.