Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 530 Bytes

README.md

File metadata and controls

22 lines (18 loc) · 530 Bytes

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