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
npm install async-exit-hook
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
118 Stars
80 Commits
15 Forks
5 Watching
6 Branches
1 Contributors
Updated on 13 Jun 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-20.7%
258,102
Compared to previous day
Last week
1.5%
1,727,587
Compared to previous week
Last month
5.4%
7,086,899
Compared to previous month
Last year
18.7%
65,112,232
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(() => { 36console.log('Sent err to cloud'); 37 }) 38 .catch(sendError => { 39console.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 © 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
75 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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@types/async-exit-hook
TypeScript definitions for async-exit-hook
log-update-async-hook
log-update fork that uses async-exit-hook internally
@jacobbubu/async-exit-hook
[![Build Status](https://github.com/jacobbubu/async-exit-hook/workflows/Build%20and%20Release/badge.svg)](https://github.com/jacobbubu/async-exit-hook/actions?query=workflow%3A%22Build+and+Release%22) [![Coverage Status](https://coveralls.io/repos/github/
exit-hook
Run some code when the process exits