在对项目文件进行多次更改后,nodemon 崩溃了吗?

nodemon is crashing after several changes done in project files?

当我更新项目文件时,出现以下问题:

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.I 手动停止所有节点服务,然后再次尝试 npm start 如果我更改端口 4001 它不起作用,它会在一段时间后再次使用相同的问题端口 4001。

2.I 增加 nodemon file watcher 的大小,但这个问题仍然没有得到解决。

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

为我修复了将 --signal SIGTERM 添加到 nodemon 命令行的问题。您可以在 nodemon project @ github.com

了解更多详情

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

  • 使 nodemon 崩溃。您应该看到类似 OP
  • 发布的错误的内容
  • 碰巧停止nodemon时点击CTRL+c
  • 输入 netstat -napt | grep [YOUR_PORT],将 [YOUR_PORT] 替换为您正在使用的端口号。在 OP 的例子中是 4000
  • 您应该让进程侦听该端口。该命令将 return 像这样:

    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 命令行将终止主进程及其所有线程,应该可以解决问题。