Express.js shutdown hook [英] Express.js shutdown hook

查看:122
本文介绍了Express.js shutdown hook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

在Express.js中,是否有一些设置回调函数在应用程序关闭时执行?您可以像这样使用node.js 核心流程退出事件

  process.on('exit',function(){
//在这里添加关闭逻辑
});

当然,主要事件循环将在退出函数返回后停止运行,因此无法安排任何来自该功能的定时器或回调(例如,任何I / O必须同步)。


In Express.js, is there someway of setting a callback function to be executed when the application shuts down?

解决方案

You could use the node.js core process 'exit' event like so:

process.on('exit', function() {
  // Add shutdown logic here.
});

Of course, the main event loop will stop running after the exit function returns so you can't schedule any timers or callbacks from within that function (e.g. any I/O must be synchronous).

这篇关于Express.js shutdown hook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆