Doing a cleanup action just before Node.js exits

后端 未结 11 1479
时光说笑
时光说笑 2020-11-22 13:54

I want to tell Node.js to always do something just before it exits, for whatever reason — Ctrl+C, an exception, or any other reason.

I tried th

11条回答
  •  悲&欢浪女
    2020-11-22 14:14

    Just wanted to mention death package here: https://github.com/jprichardson/node-death

    Example:

    var ON_DEATH = require('death')({uncaughtException: true}); //this is intentionally ugly
    
    ON_DEATH(function(signal, err) {
      //clean up code here
    })
    

提交回复
热议问题