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:
parent
57ed7c33b1
commit
ed24b8f10a
@ -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
|
The `'beforeExit'` should *not* be used as an alternative to the `'exit'` event
|
||||||
unless the intention is to schedule additional work.
|
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'
|
### Event: 'disconnect'
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.7.7
|
added: v0.7.7
|
||||||
|
Loading…
x
Reference in New Issue
Block a user