Socket
Socket
Sign inDemoInstall

node-cleanup

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-cleanup

installs a cleanup handler that always runs on exiting node


Version published
Weekly downloads
1.1M
increased by6.19%
Maintainers
1
Weekly downloads
 
Created

What is node-cleanup?

The node-cleanup package allows you to handle cleanup tasks when your Node.js process is exiting. This can be useful for tasks such as closing database connections, clearing temporary files, or other necessary cleanup operations.

What are node-cleanup's main functionalities?

Basic Cleanup Handler

This feature allows you to register a basic cleanup handler that will be called when the Node.js process is exiting. You can perform any necessary cleanup tasks within this handler.

const nodeCleanup = require('node-cleanup');

nodeCleanup(function (exitCode, signal) {
  console.log('Cleaning up before exit...');
  // Perform cleanup tasks here
});

Custom Exit Code

This feature allows you to customize the exit code of the process. By returning false from the cleanup handler, you can prevent the default exit code from being used.

const nodeCleanup = require('node-cleanup');

nodeCleanup(function (exitCode, signal) {
  console.log('Cleaning up before exit...');
  // Perform cleanup tasks here
  return false; // Prevents the default exit code
});

Signal Handling

This feature allows you to handle specific signals (e.g., SIGINT, SIGTERM) and perform cleanup tasks accordingly. You can also re-emit the signal if needed.

const nodeCleanup = require('node-cleanup');

nodeCleanup(function (exitCode, signal) {
  if (signal) {
    console.log(`Received signal: ${signal}`);
    // Perform cleanup tasks here
    process.kill(process.pid, signal);
    return false;
  }
});

Other packages similar to node-cleanup

Keywords

FAQs

Package last updated on 27 Sep 2016

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