on-shutdown.js 291 B

123456789101112131415
  1. module.exports = function (fn) {
  2. const cleanup = () => {
  3. try {
  4. fn()
  5. } finally {
  6. process.exit()
  7. }
  8. }
  9. process.on('exit', cleanup)
  10. process.on('SIGINT', cleanup)
  11. process.on('SIGTERM', cleanup)
  12. process.on('SIGHUP', cleanup)
  13. process.on('SIGBREAK', cleanup)
  14. }