如何在SIGINT上停止node.js检查器/Chrome调试器? [英] How to stop the node.js inspector / Chrome Debugger on SIGINT?

查看:182
本文介绍了如何在SIGINT上停止node.js检查器/Chrome调试器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码从终端捕获^ C并正常关闭Express应用程序:

I have the following code to capture a ^C from the terminal and gracefully shutdown my Express app:

process.on('SIGINT', () => {
    console.log('SIGINT received ...');
    console.log('Shutting down the server');

    server.close(() => {
        console.log('Server has been shutdown');
        console.log('Exiting process ...');
        process.exit(0);
    });
});

但是,如果我使用--inspect启动节点实例,则以上代码将无法停止检查器和Chrome调试器.重新启动应用程序时,出现以下错误:

However if I start my node instance with --inspect, then the above code fails to stop the inspector and the Chrome debugger. When I restart my application, I get the following error:

Starting inspector on 127.0.0.1:9229 failed: address already in use

如何正常停止我的应用程序以避免发生此错误?

How do I gracefully stop my app to avoid this error?

此处可用的完整代码./p>

Full code available here.

推荐答案

似乎VSCode,Puppeteer,nodemon,express等导致了此问题, 您在后台运行了一个进程,或者只是关闭了调试区域(浏览器,终端等),或其他任何东西, 无论如何,您都可以在CMD中运行

It seems that VSCode, Puppeteer, nodemon, express, etc. causes this problem, you ran a process in the background or just closed the debugging area [browser, terminal, etc. ] or whatever , anyway, you can in CMD run

$ ps ax | grep node

然后

$ killall -9 node

这不是最好的解决方案,而且,我可能建议您使用此端口查找进程,然后发送关闭信号

it is not the best solution, also, i may suggest that you look for the process using this port then send close signal

$ sudo ss -lptn 'sport = :9229'

OR

$ sudo netstat -nlp | grep :9229

$ sudo lsof -n -i :9229 | grep LISTEN

时间:

$ sudo kill <pid>

或只需[将两个步骤合为一体]

OR JUST [the two steps in one]

$ sudo kill `sudo lsof -t -i:9229`

OR

$ sudo kill $(sudo lsof -t -i:9229)

这篇关于如何在SIGINT上停止node.js检查器/Chrome调试器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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