Nodejs地址已在用途:::5000

h7appiyu  于 12个月前  发布在  Node.js
关注(0)|答案(5)|浏览(115)

我正在尝试运行一个节点应用程序。我运行node app.js。当我这样做时,我得到这个错误:

node:events:346
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::5000
    at Server.setupListenHandle [as _listen2] (node:net:1311:16)
    at listenInCluster (node:net:1359:12)
    at Server.listen (node:net:1446:7)

Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1338:8)
    at processTicksAndRejections (node:internal/process/task_queues:81:21) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '::',
  port: 5000
}

我花了几个小时在网上寻找可能的解决方案,但到目前为止没有一个有效。相同的代码库在不同的机器上工作得很好。此错误发生在Mac M1芯片上。
有人知道怎么解决吗?
我试着找到在5000上运行的进程,我试着杀死它们等等。到目前为止都没有成功。我正在运行node 15.14.0
我在M1 Chip上运行macOS Monterey
如何修复此错误?

i86rm4rw

i86rm4rw1#

你应该在Mac上禁用AirPlay。因为macOS Monterey开始监听端口5000和8000。

  • 系统偏好设置>共享>取消选中AirPlay接收器 *

对于macOS Ventura

  • 系统设置>常规>禁用Airplay接收器 *
pcrecxhr

pcrecxhr2#

Lee Jeonghyun是对的。kill -9 PID永远不会工作的原因是:
https://developer.apple.com/forums/thread/682332
Monterey 的控制中心也在监听5000
我在nodejs应用程序中更改了端口号,应用程序又开始工作了。

7gs2gvoe

7gs2gvoe3#

列出Mac上的所有进程:

sudo lsof -PiTCP -sTCP:LISTEN

您将看到进程及其端口的列表。在5000端口或错误中的任何其他端口上选择进程PID:[*] EADDRINUSE:地址已在使用中...**
最后杀死它,如果它不是一个重要的应用程序给你

kill -9 1234
jc3wubiy

jc3wubiy4#

这也发生在我从大苏尔升级到macOS Monterey之后。
我传递给Node应用程序的每个端口似乎都已经在使用中。
您需要在Mac上禁用AirPlay。
系统偏好设置>共享>取消选中AirPlay接收器
Screenshot

xwbd5t1u

xwbd5t1u5#

做了一些调查,发现macOS Monterey正在使用Airplay-Receiver的5000端口。如果你真的想使用该端口,请在“系统偏好设置->共享”中禁用该功能。
下面这篇文章帮助了我:Port 5000 already in use — MacOS Monterey issue

相关问题