我正在构建具有Front-React和Backend Express的应用程序。我正在尝试同时运行两者。我在后端编辑了pakage.json文件。我的主文件夹前端和后端文件夹中有两个文件夹。当我尝试运行它时,它给出一个错误。如何解决此错误?谢谢。
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"client": "cd frontend && npm start",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "Ezana",
"license": "ISC",
"dependencies": {
"concurrently": "^4.1.0",
"express": "^4.16.4",
"nodemon": "^1.18.10"
}
}
[0] Error: listen EADDRINUSE: address already in use :::5000
[0] at Server.setupListenHandle [as _listen2] (net.js:1277:14)
[0] at listenInCluster (net.js:1325:12)
[0] at Server.listen (net.js:1412:7)
[0] at Function.listen (/Users/ezanatesfaye/Desktop/Canvas/backend/node_modules/express/lib/application.js:618:24)
[0] at Object.<anonymous> (/Users/ezanatesfaye/Desktop/Canvas/backend/index.js:25:5)
[0] at Module._compile (internal/modules/cjs/loader.js:689:30)
[0] at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
[0] at Module.load (internal/modules/cjs/loader.js:599:32)
[0] at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
[0] at Function.Module._load (internal/modules/cjs/loader.js:530:3)
[0] Emitted 'error' event at:
[0] at emitErrorNT (net.js:1304:8)
[0] at process._tickCallback (internal/process/next_tick.js:63:19)
[0] at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
[0] at startup (internal/bootstrap/node.js:283:19)
[0] at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
答案 0 :(得分:0)
那是因为您已经有一个绑定到端口5000的进程。我认为您之前已经运行了相同的东西,并且可能该进程仍被分配了相同的端口。尝试杀死进程 OR 并在其他端口上监听服务器。从此开始,将其添加到服务器端代码:-
yr_rules_scan_mem
并且始终记得通过发送请求const A_PORT = 6000;
app.listen(A_PORT, () => console.log(`LISTENING ON PORT ${A_PORT}`));
通过CTRL + C
正确终止该过程。
答案 1 :(得分:0)
杀死您在端口5000
中运行的应用程序,或更改节点应用程序的端口。您也可以使用以下配置。
"scripts": {
"test": "jest",
"start": "node index.js",
"start-dev": "nodemon index.js",
"client-install": "npm install --prefix client",
"client": "npm start --prefix ../client",
"dev": "concurrently \"npm run start-dev\" \"npm run client\""
},
答案 2 :(得分:0)
您可以尝试此npm-run-all --parallel start-dev client
在执行上述脚本之前,请先安装npm-run-all: "^4.1.3"
。
或者您可以尝试npm run start-dev && npm run client