Skip to content

tombl/before-shutdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Execute an async handler before the Node.js process exits

Resources

License

Stars

Watchers

Forks

Packages

No packages published