From ca83b2736e2b7c0f8fe1d4d0639bd00d7fb1ea54 Mon Sep 17 00:00:00 2001 From: Vickodev Date: Tue, 25 Jun 2019 17:08:02 -0500 Subject: [PATCH] doc: add example for beforeExit event PR-URL: https://github.com/nodejs/node/pull/28430 Reviewed-By: Rich Trott Reviewed-By: Trivikram Kamat Reviewed-By: Colin Ihrig --- doc/api/process.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/api/process.md b/doc/api/process.md index 826877381ceeb8..aa7477d3bc5962 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -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'