🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

capture-exit

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capture-exit

safely cleanup in signal handlers

2.0.0
latest
100

Supply Chain Security

100

Vulnerability

78

Quality

81

Maintenance

100

License

Version published
Weekly downloads
5.5M
-0.84%
Maintainers
4
Weekly downloads
 
Created

What is capture-exit?

The capture-exit npm package is designed to enable graceful shutdown and cleanup of Node.js processes by capturing and managing exit signals. It allows developers to register multiple cleanup functions that will be executed when the process exits, either normally or due to an uncaught exception, or when signals like SIGTERM or SIGINT are received. This is particularly useful for ensuring that resources are properly released and that critical finalization steps are completed before the process exits.

What are capture-exit's main functionalities?

Registering cleanup functions

This feature allows developers to register functions that will be executed when the process exits. The code sample demonstrates how to register a simple cleanup function that logs a message to the console before the process exits.

const captureExit = require('capture-exit');
captureExit.captureExit();

function cleanup() {
  console.log('Cleanup code executed before exit.');
}

captureExit.onExit(cleanup);

Handling multiple cleanup functions

This feature supports the registration of multiple cleanup functions. The code sample shows how to register two separate functions to handle different cleanup tasks, such as closing database connections and clearing cache.

const captureExit = require('capture-exit');
captureExit.captureExit();

function cleanupDatabase() {
  console.log('Database connections closed.');
}

function cleanupCache() {
  console.log('Cache cleared.');
}

captureExit.onExit(cleanupDatabase);
captureExit.onExit(cleanupCache);

Other packages similar to capture-exit

FAQs

Package last updated on 21 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts