gpt4 book ai didi

node.js - 在项目文件中进行多次更改后,nodemon 崩溃了?

转载 作者:行者123 更新时间:2023-12-02 13:03:30 26 4
gpt4 key购买 nike

当我更新项目文件时,我遇到以下问题:

events.js:183
throw er; // Unhandled 'error' event
^

Error: listen EADDRINUSE :::4000
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at Server.setupListenHandle [as _listen2] (net.js:1351:14)
at listenInCluster (net.js:1392:12)
at Server.listen (net.js:1476:7)
at Function.listen (E:\nodejs-mysql-authentication- master\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (E:\nodejs-mysql-authentication-master\server.js:26:5)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
[nodemon] app crashed - waiting for file changes before starting...

我已经尝试了所有这些来解决下面给出的这个问题

1.我手动停止所有 Node 服务,然后再次尝试 npm start 如果我更改端口 4001 它不起作用,之后它会工作,有时再次出现相同的问题端口 4001。

2.我增加了nodemon文件观察器的大小,但这个问题仍然没有得到解决。

但是当我再次重新启动我的电脑时,nodemon 正在同一端口上工作。那么如果我不想更改端口并且无法重新启动我的电脑,我该如何解决这个问题。

最佳答案

--signal SIGTERM 添加到为我修复的 nodemon 命令行。您可以通过nodemon project @ github.com了解更多详情

出现此问题的原因是,当 nodemon 重新启动应用程序时,线程仍在运行,并且该线程已在使用您要使用的端口。您可以通过以下步骤确认这一点:

  • 使nodemon崩溃。您应该看到类似于 OP 发布的错误的内容
  • 当nodemon停止时按CTRL+c
  • 输入netstat -napt | grep [YOUR_PORT],将 [YOUR_PORT] 替换为您正在使用的端口号。在OP的例子中是4000
  • 您应该让进程监听该端口。该命令将返回如下内容:

    ff@darkpc:~/dev/dp/graphql/teste1> netstat -napt | grep 4000
    (Not all processes could be identified, non-owned process info
    will not be shown, you would have to be root to see it all.)
    tcp6 0 0 :::4000 :::* LISTEN 31837/node8
  • 如果您尝试再次运行nodemon,它将崩溃!

  • 通过kill 31837杀死使用您的端口的进程,在这种情况下,31387是node8的PID,如上面所示
  • 再次运行nodemon就可以了。

--signal SIGTERM 添加到 nodemon 命令行将终止主进程及其所有线程,并且应该可以解决问题。

关于node.js - 在项目文件中进行多次更改后,nodemon 崩溃了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51588095/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com