0.0.2 • Published 2 years ago

before-shutdown v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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
0.0.2

2 years ago

0.0.1

2 years ago