From a28db5f4706e4bc8ecbcbf0d2414b339033718a3 Mon Sep 17 00:00:00 2001 From: Laura Ciro Date: Fri, 21 Jun 2019 17:55:37 -0500 Subject: [PATCH] doc: add example of event close for child_process PR-URL: https://github.com/nodejs/node/pull/28376 Reviewed-By: James M Snell Reviewed-By: Rich Trott --- doc/api/child_process.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/api/child_process.md b/doc/api/child_process.md index 2c829fa1576f58..7945c93bf0daf0 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -914,6 +914,23 @@ The `'close'` event is emitted when the stdio streams of a child process have been closed. This is distinct from the [`'exit'`][] event, since multiple processes might share the same stdio streams. +```js +const { spawn } = require('child_process'); +const ls = spawn('ls', ['-lh', '/usr']); + +ls.stdout.on('data', (data) => { + console.log(`stdout: ${data}`); +}); + +ls.on('close', (code) => { + console.log(`child process close all stdio with code ${code}`); +}); + +ls.on('exit', (code) => { + console.log(`child process exited with code ${code}`); +}); +``` + ### Event: 'disconnect'