before-shutdown
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

before-shutdown

Execute an async handler before the Node.js process exits

import { beforeShutdown } from "before-shutdown";
import { setTimeout } from "timers/promises";

// calls the provided function prior to exiting
const unregister = beforeShutdown(async () => {
  // your async operation here
  console.log("Cleaning up...")
  await setTimeout(1000);
});

unregister(); // removes the hook

Supported exit methods:

  • process.exit()
  • thrown exception
  • getting to the end of the program
  • ctrl-c/signals

/before-shutdown/

    Package Sidebar

    Install

    npm i before-shutdown

    Weekly Downloads

    0

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    7.23 kB

    Total Files

    6

    Last publish

    Collaborators

    • tombl