Socket
Socket
Sign inDemoInstall

capture-exit

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capture-exit

safely cleanup in signal handlers


Version published
Weekly downloads
4M
decreased by-2.14%
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc