JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5204871
  • Score
    100M100P100Q210977F
  • License MIT

Run some code when the process exits

Package Exports

  • exit-hook

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (exit-hook) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

exit-hook

Run some code when the process exits

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

This package is useful for cleaning up before exiting.

Install

$ npm install 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');
});

throw new Error('🦄');

//=> 'Exiting'
//=> 'Exiting 2'

Removing an exit hook:

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

const unsubscribe = exitHook(() => {});

unsubscribe();

API

exitHook(callback)

Returns a function that removes the hook when called.

callback

Type: Function

The callback to execute when the process exits.


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.