【问题标题】:Port 3000 already in use. Nodejs, Socket,IO端口 3000 已在使用中。 Nodejs,套接字,IO
【发布时间】:2021-09-27 10:49:23
【问题描述】:

除此之外没有其他进程在端口 3000 上运行

这是程序的一部分

const port = process.env.port || 3000;

app.listen((port), () => console.log(`listening to port ${port}`));

const io = require("socket.io")(port) //Here's the problem. 

添加端口 3000 时出现问题

如果我手动编写一些其他端口,例如 4000。它可以工作

我要不要为 socket.io 创建另一个端口?

如果是端口 3000

错误如下所示

listening to port 3000
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::3000

Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1345:8)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '::',
  port: 3000
}
[nodemon] app crashed - waiting for file changes before starting...

【问题讨论】:

标签: node.js socket.io port


【解决方案1】:

在终端尝试这个来找到活动端口:

Windows

netstat -ano | findstr :3000

Mac/Linux

lsof -iTCP:3000 -sTCP:LISTEN

然后使用 PID 杀死:

kill <PID>

如果上述方法不起作用,则这样做

kill -9 <PID>

【讨论】:

  • isof 无法被终端识别。我用窗户
  • 改用netstat -ano | findstr :3000
  • 3000 只在这个项目上运行。
【解决方案2】:

表示有一个进程使用3000端口,尝试杀死该进程并重新启动应用程序。

【讨论】:

  • 这是一个项目,它都在 3000 上运行
  • 当您想重新启动时,您的项目可能仍在后台运行。
猜你喜欢
  • 2019-10-28
  • 1970-01-01
  • 1970-01-01
  • 2016-08-27
  • 2015-04-23
  • 2017-08-16
  • 2021-07-02
  • 1970-01-01
  • 2013-04-17
相关资源
最近更新 更多