Socket
Socket
Sign inDemoInstall

exit-hook

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    exit-hook

Run some code when the process exits


Version published
Maintainers
1
Install size
2.63 kB
Created

Package description

What is exit-hook?

The exit-hook npm package allows developers to easily register callbacks to be executed when a Node.js process exits. This can be particularly useful for cleaning up resources, saving state, or performing other shutdown tasks in a Node.js application.

What are exit-hook's main functionalities?

Registering a simple exit hook

This feature allows you to register a callback function that will be called when the process exits. The code sample demonstrates how to register a simple exit hook that logs a message to the console when the process exits.

const exitHook = require('exit-hook');
exitHook(() => {
  console.log('Process is exiting');
});

Unregistering an exit hook

This feature allows for the deregistration of an exit hook. The code sample shows how to register an exit hook and then later unregister it, preventing the callback from being called when the process exits.

const exitHook = require('exit-hook');
const unsubscribe = exitHook(() => {
  console.log('Process is exiting');
});

// Later in the code, to unregister the hook
disconnect();

Other packages similar to exit-hook

Readme

Source

exit-hook Build Status

Run some code when the process exits

The process.on('exit') event doesn't catch all the ways a process can exit.

Useful for cleaning up.

Install

$ npm install --save exit-hook

Usage

var exitHook = require('exit-hook');

exitHook(function () {
	console.log('exiting');
});

// you can add multiple hooks, even across files
exitHook(function () {
	console.log('exiting 2');
});

throw new Error('unicorns');

//=> exiting
//=> exiting 2

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 01 Sep 2014

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc