节点:事件:304 错误:监听 EADDRINUSE:地址已在使用 :::5000

Posted

技术标签:

【中文标题】节点:事件:304 错误:监听 EADDRINUSE:地址已在使用 :::5000【英文标题】:node:events:304 Error: listen EADDRINUSE: address already in use :::5000 【发布时间】:2021-09-14 21:40:15 【问题描述】:

我尝试同时使用同时运行服务器和客户端,然后我得到了这个错误,即使我在网上尝试了很多解决方案,检查了没有5000端口运行,删除模块,yarn.lock,清理缓存,重新启动我的电脑等,错误仍然存​​在。

package.json


  "name": "SPACEX_LAUNCH_STATS",
  "version": "1.0.0",
  "description": "App that lists SpaceX launch missions",
  "main": "server.js",
  "scripts": 
    "start": "node server.js",
    "server": "nodemon server.js",
    "client": "yarn start --prefix client",
    "dev": "concurrently \"yarn run server\" \"yarn run client\""
  ,
  "author": "admin",
  "license": "MIT",
  "dependencies": 
    "axios": "^0.21.1",
    "concurrently": "^6.2.0",
    "express": "^4.17.1",
    "express-graphql": "^0.12.0",
    "graphql": "^15.5.1"
  ,
  "devDependencies": 
    "nodemon": "^2.0.7"
  


error

Temps-MacBook-Pro:SPACEX_LAUNCH_STATS tempuser$ yarn run dev
yarn run v1.22.10
warning ../../../../package.json: No license field
$ concurrently "yarn run server" "yarn run client"
warning ../../../../package.json: No license field
warning ../../../../package.json: No license field
$ yarn start --prefix client
$ nodemon server.js
warning ../../../../package.json: No license field
[0] [nodemon] 2.0.9
[0] [nodemon] to restart at any time, enter `rs`
[0] [nodemon] watching path(s): *.*
[0] [nodemon] watching extensions: js,mjs,json
[0] [nodemon] starting `node server.js`
$ node server.js --prefix client
[0] Server started on port 5000
[1] node:events:304
[1]       throw er; // Unhandled 'error' event
[1]       ^
[1] 
[1] Error: listen EADDRINUSE: address already in use :::5000
[1]     at Server.setupListenHandle [as _listen2] (node:net:1286:16)
[1]     at listenInCluster (node:net:1334:12)
[1]     at Server.listen (node:net:1420:7)
[1]     at Function.listen (/Users/tempuser/Documents/React/spaceX/SPACEX_LAUNCH_STATS/node_modules/express/lib/application.js:618:24)
[1]     at Object.<anonymous> (/Users/tempuser/Documents/React/spaceX/SPACEX_LAUNCH_STATS/server.js:17:5)
[1]     at Module._compile (node:internal/modules/cjs/loader:1083:30)
[1]     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
[1]     at Module.load (node:internal/modules/cjs/loader:948:32)
[1]     at Function.Module._load (node:internal/modules/cjs/loader:789:14)
[1]     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)
[1] Emitted 'error' event on Server instance at:
[1]     at emitErrorNT (node:net:1313:8)
[1]     at processTicksAndRejections (node:internal/process/task_queues:80:21) 
[1]   code: 'EADDRINUSE',
[1]   errno: -48,
[1]   syscall: 'listen',
[1]   address: '::',
[1]   port: 5000
[1] 
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[1] yarn run client exited with code 1

可疑的一点是我能够杀死所有端口,但有一个是不可杀死的。它说“没有这样的过程”。我不确定这是否是隐藏在幕后某处的正在运行的端口。这是屏幕截图。请帮忙。

No such process

【问题讨论】:

没有人喜欢看代码图片。请将您的代码复制并粘贴到这篇文章中。 您正在并发调用相同的脚本(server.js),这意味着它将尝试使用相同的端口。你能说出yarn client 的用途吗?如果您在不同的端口和不同的上下文中运行脚本,则可以实现并发。 除非您显示一些代码,否则没有人可以肯定地说,但似乎,当您使用 --client 标志启动时,您的 server.js 会尝试为端口 5000 创建侦听器 @code 添加。 @Apoorva Chikara @derpischer yarn client 用于启动 react-app 的前端服务器。我尝试单独删除包含“server.js”的“重复”脚本,然后运行它,但错误消息仍然存在。 【参考方案1】:

我将 "dev": "concurrently \"yarn run server\" \"yarn run client\"" 更改为 "dev": "concurrently \"npm run server\" \"npm run client\"",现在一切正常。我不知道为什么,但是端口 3000 和 5000 现在都可以运行了

【讨论】:

以上是关于节点:事件:304 错误:监听 EADDRINUSE:地址已在使用 :::5000的主要内容,如果未能解决你的问题,请参考以下文章

初学zookeeper--自定义事件监听

时间绑定和事件监听!

js如何清除dom节点上的指定监听事件?

JQuery 节点监听

Zookeeper之Watcher监听事件丢失分析

activiti--事件监听