mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
doc: add example for beforeExit event
PR-URL: https://github.com/nodejs/node/pull/28430 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
1 parent
44acec5386
commit
ca83b2736e
1 file changed
+17
@@ -36,6 +36,23 @@ termination, such as calling [`process.exit()`][] or uncaught exceptions.
|
||||
The `'beforeExit'` should *not* be used as an alternative to the `'exit'` event
|
||||
unless the intention is to schedule additional work.
|
||||
|
||||
```js
|
||||
process.on('beforeExit', (code) => {
|
||||
console.log('Process beforeExit event with code: ', code);
|
||||
});
|
||||
|
||||
process.on('exit', (code) => {
|
||||
console.log('Process exit event with code: ', code);
|
||||
});
|
||||
|
||||
console.log('This message is displayed first.');
|
||||
|
||||
// Prints:
|
||||
// This message is displayed first.
|
||||
// Process beforeExit event with code: 0
|
||||
// Process exit event with code: 0
|
||||
```
|
||||
|
||||
### Event: 'disconnect'
|
||||
<!-- YAML
|
||||
added: v0.7.7
|
||||
|
||||
Reference in new issue
Block a user