New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pm2-exit-hook

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pm2-exit-hook

Run some code when the process exits (supports pm2 clustering)

  • 2.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

pm2-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. This module catches:

  • process SIGINT, SIGTERM and SIGHUP signals
  • process beforeExit and exit events
  • PM2 clustering process shutdown message (PM2 graceful reload)

Useful for cleaning up. You can also include async handlers.

Forked from exit-hook Supports pm2 cluster mode.

Install

$ npm install --save pm2-exit-hook

Usage

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

exitHook(() => {
	console.log('exiting');
});

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

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

// you can add async hooks by accepting a callback
exitHook(callback => {
	setTimeout(() => {
		console.log('exiting 3');
		callback();
	}, 1000);
});

throw new Error('unicorns');

//=> 'exiting'
//=> 'exiting 2'
//=> 'exiting 3'

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 08 Mar 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