Skip to content

Commit dd93730

Browse files
VickodevTrott
Vickodev
authored andcommitted
doc: add example for beforeExit event
1 parent 3ad8799 commit dd93730

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

doc/api/process.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ termination, such as calling [`process.exit()`][] or uncaught exceptions.
3636
The `'beforeExit'` should *not* be used as an alternative to the `'exit'` event
3737
unless the intention is to schedule additional work.
3838

39+
```js
40+
process.on('beforeExit', (code) => {
41+
console.log('Process beforeExit event with code: ', code);
42+
});
43+
44+
process.on('exit', (code) => {
45+
console.log('Process exit event with code: ', code);
46+
});
47+
48+
console.log('This message is displayed first.');
49+
50+
// Prints:
51+
// This message is displayed first.
52+
// Process beforeExit event with code: 0
53+
// Process exit event with code: 0
54+
```
55+
3956
### Event: 'disconnect'
4057
<!-- YAML
4158
added: v0.7.7

0 commit comments

Comments
 (0)