【问题标题】:Stopping Node.js gracefully优雅地停止 Node.js
【发布时间】:2018-02-24 03:11:47
【问题描述】:

如何优雅地停止 Node.js 应用程序?

我需要在终止之前将我的内存内容写入文件,在接收到终止信号(例如,SIGINT(2),SIGTERM(3))时,以便进行“优雅关闭”。怎么做?

PS。 这与Quitting node.js gracefully 不是同一个问题,因为问题是错误的,使用ctrl+z 而不是ctrl+c,答案不包括处理杀死信号。

【问题讨论】:

    标签: node.js signals exit terminate


    【解决方案1】:

    您可以使用

    收听exitSIGINT
    process.on("exit", () => /* this will be called on the exit event */);
    
    
    process.on("SIGINT", () => /* this will be called on the SIGINT event */);
    

    【讨论】:

      猜你喜欢
      • 2010-11-05
      • 1970-01-01
      • 2018-09-27
      • 2019-11-10
      • 1970-01-01
      • 2010-12-15
      • 2018-09-08
      • 2021-06-04
      • 1970-01-01
      相关资源
      最近更新 更多