Register callback on node process signals.
@jsenv/node-signals
was designed to cleanup things (gracefully if possible), when node process exits.
npm install @jsenv/[email protected]
import { teardownSignal } from "@jsenv/node-signals"
teardownSignal.addCallback((reason) => {
console.log(`teardown because ${reason}`)
})
For node < 13
const { teardownSignal } = require("@jsenv/node-signals")