Gathering detailed insights and metrics for async-exit-hook
Gathering detailed insights and metrics for async-exit-hook
Gathering detailed insights and metrics for async-exit-hook
Gathering detailed insights and metrics for async-exit-hook
exit-hook
Run some code when the process exits
@types/async-exit-hook
TypeScript definitions for async-exit-hook
log-update-async-hook
log-update fork that uses async-exit-hook internally
async-exit-hook-improved
Run some code when the process exits (supports async hooks and pm2 clustering)
npm install async-exit-hook
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.8
Supply Chain
99.4
Quality
75.3
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
260,709,034
Last Day
27,297
Last Week
27,297
Last Month
5,111,478
Last Year
66,990,710
118 Stars
80 Commits
15 Forks
5 Watching
6 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
2.0.1
Package Id
async-exit-hook@2.0.1
Size
4.55 kB
NPM Version
5.3.0
Node Version
6.11.2
Publised On
03 Aug 2017
Cumulative downloads
Total Downloads
Last day
0%
27,297
Compared to previous day
Last week
-97.7%
27,297
Compared to previous week
Last month
-7%
5,111,478
Compared to previous month
Last year
19.1%
66,990,710
Compared to previous year
5
Run some code when the process exits
The process.on('exit')
event doesn't catch all the ways a process can exit. This module catches:
Useful for cleaning up. You can also include async handlers, and add custom events to hook and exit on.
Forked and pretty much rewritten from exit-hook.
$ npm install --save async-exit-hook
process.exit()
and asynchronous codeIf you use asynchronous exit hooks, DO NOT use process.exit()
to exit.
The exit
event DOES NOT support asynchronous code.
['beforeExit' is not emitted for conditions causing explicit termination, such as process.exit()] (https://nodejs.org/api/process.html#process_event_beforeexit)
process.kill(signal)
On windows process.kill(signal)
immediately kills the process, and does not fire signal events,
and as such, cannot be used to gracefully exit. See Clustering and child processes for a
workaround when killing child processes. I'm planning to support gracefully exiting
with async support on windows soon.
If you use custom clustering / child processes, you can gracefully shutdown your child process
by sending a shutdown message (childProc.send('shutdown')
).
1const exitHook = require('async-exit-hook'); 2 3exitHook(() => { 4 console.log('exiting'); 5}); 6 7// you can add multiple hooks, even across files 8exitHook(() => { 9 console.log('exiting 2'); 10}); 11 12// you can add async hooks by accepting a callback 13exitHook(callback => { 14 setTimeout(() => { 15 console.log('exiting 3'); 16 callback(); 17 }, 1000); 18}); 19 20// You can hook uncaught errors with uncaughtExceptionHandler(), consequently adding 21// async support to uncaught errors (normally uncaught errors result in a synchronous exit). 22exitHook.uncaughtExceptionHandler(err => { 23 console.error(err); 24}); 25 26// You can hook unhandled rejections with unhandledRejectionHandler() 27exitHook.unhandledRejectionHandler(err => { 28 console.error(err); 29}); 30 31// You can add multiple uncaught error handlers 32// Add the second parameter (callback) to indicate async hooks 33exitHook.uncaughtExceptionHandler((err, callback) => { 34 sendErrorToCloudOrWhatever(err) // Returns promise 35 .then(() => { 36 console.log('Sent err to cloud'); 37 }); 38 .catch(sendError => { 39 console.error('Error sending to cloud: ', err.stack)); 40 }) 41 .then(() => callback); 42 }); 43}); 44 45// Add exit hooks for a signal or custom message: 46 47// Custom signal 48// Arguments are `signal, exitCode` (SIGBREAK is already handled, this is an example) 49exitHook.hookEvent('SIGBREAK', 21); 50 51// process event: `message` with a filter 52// filter gets all arguments passed to *handler*: `process.on(message, *handler*)` 53// Exits on process event `message` with msg `customShutdownMessage` only 54exitHook.hookEvent('message', 0, msg => msg !== 'customShutdownMessage'); 55 56// All async hooks will work with uncaught errors when you have specified an uncaughtExceptionHandler 57throw new Error('awesome'); 58 59//=> // Sync uncaughtExcpetion hooks called and retun 60//=> '[Error: awesome]' 61//=> // Sync hooks called and retun 62//=> 'exiting' 63//=> 'exiting 2' 64//=> // Async uncaughtException hooks return 65//=> 'Sent error to cloud' 66//=> // Sync uncaughtException hooks return 67//=> 'exiting 3'
MIT © Tapani Moilanen
MIT © Sindre Sorhus
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/28 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
76 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More