Gathering detailed insights and metrics for @jacobbubu/async-exit-hook
Gathering detailed insights and metrics for @jacobbubu/async-exit-hook
Gathering detailed insights and metrics for @jacobbubu/async-exit-hook
Gathering detailed insights and metrics for @jacobbubu/async-exit-hook
npm install @jacobbubu/async-exit-hook
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (98.66%)
JavaScript (1.34%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Sep 30, 2020
Latest Version
1.0.0
Package Id
@jacobbubu/async-exit-hook@1.0.0
Unpacked Size
17.00 kB
Size
6.13 kB
File Count
6
NPM Version
6.14.6
Node Version
12.18.4
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
30
Run some code when the process exits. async-exit-hook rewritten in TypeScript.
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 rewritten from 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')
).
1import exitHook from '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((err, cb) => { 14 setTimeout(() => { 15 console.log('exiting 3'); 16 cb(); 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// Add exit hooks for a signal or custom message: 45 46// Custom signal 47// Arguments are `signal, exitCode` (SIGBREAK is already handled, this is an example) 48exitHook.hookEvent('SIGBREAK', 21); 49 50// process event: `message` with a filter 51// filter gets all arguments passed to *handler*: `process.on(message, *handler*)` 52// Exits on process event `message` with msg `customShutdownMessage` only 53exitHook.hookEvent('message', 0, msg => msg !== 'customShutdownMessage'); 54 55// All async hooks will work with uncaught errors when you have specified an uncaughtExceptionHandler 56throw new Error('awesome'); 57 58//=> // Sync uncaughtExcpetion hooks called and retun 59//=> '[Error: awesome]' 60//=> // Sync hooks called and retun 61//=> 'exiting' 62//=> 'exiting 2' 63//=> // Async uncaughtException hooks return 64//=> 'Sent error to cloud' 65//=> // Sync uncaughtException hooks return 66//=> 'exiting 3'
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
Found 0/1 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
42 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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