Skip to content

Commit

Permalink
doc: add example for beforeExit event
Browse files Browse the repository at this point in the history
PR-URL: #28430
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Vickodev authored and targos committed Jul 20, 2019
1 parent 44acec5 commit ca83b27
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ca83b27

Please sign in to comment.