Skip to content

Commit a28db5f

Browse files
ltcirotargos
authored andcommitted
doc: add example of event close for child_process
PR-URL: #28376 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent fa82cbc commit a28db5f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

doc/api/child_process.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,23 @@ The `'close'` event is emitted when the stdio streams of a child process have
914914
been closed. This is distinct from the [`'exit'`][] event, since multiple
915915
processes might share the same stdio streams.
916916

917+
```js
918+
const { spawn } = require('child_process');
919+
const ls = spawn('ls', ['-lh', '/usr']);
920+
921+
ls.stdout.on('data', (data) => {
922+
console.log(`stdout: ${data}`);
923+
});
924+
925+
ls.on('close', (code) => {
926+
console.log(`child process close all stdio with code ${code}`);
927+
});
928+
929+
ls.on('exit', (code) => {
930+
console.log(`child process exited with code ${code}`);
931+
});
932+
```
933+
917934
### Event: 'disconnect'
918935
<!-- YAML
919936
added: v0.7.2

0 commit comments

Comments
 (0)