本文介绍了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
发布评论