diff --git a/doc/api/child_process.md b/doc/api/child_process.md index 9112e72e063c9f..dab853c0bfff8c 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -140,13 +140,13 @@ generated output. ```js const exec = require('child_process').exec; -const child = exec('cat *.js bad_file | wc -l', - (error, stdout, stderr) => { - console.log(`stdout: ${stdout}`); - console.log(`stderr: ${stderr}`); - if (error !== null) { - console.log(`exec error: ${error}`); - } +exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`); + return; + } + console.log(`stdout: ${stdout}`); + console.log(`stderr: ${stderr}`); }); ```