我正在创建一个项目,并使用nodejs表示后端. 一切正常,但是当我在文件中进行任何更改时,由于以下错误,nodemon无法重新启动服务器:
I'm creating a project and using nodejs, express for the backend. Everything works fine but as I make any change in the file, nodemon is unable to restart the server due to following error:
Error: listen EADDRINUSE: address already in use :::5000
index.js:
const express = require("express"); const morgan = require("morgan"); const mongoose = require("mongoose"); const cookieParser = require("cookie-parser"); const session = require("express-session"); const FileStore = require("session-file-store")(session); const dotenv = require("dotenv"); var passport = require("passport"); dotenv.config(); const PORT = process.env.PORT || 5000; const app = express(); ..... app.listen(PORT, () => console.log(`Server listening on port ${PORT}!`));package.json
{ "name": "chat-app-backend", "version": "0.0.0", "private": true, "scripts": { "start": "node index.js", "dev": "nodemon --ignore 'sessions/' index.js" }, "dependencies": { "bcryptjs": "^2.4.3", "cookie-parser": "^1.4.5", "cors": "^2.8.5", "debug": "~2.6.9", "dotenv": "^8.2.0", "express": "~4.16.0", "express-session": "^1.17.0", "http-errors": "~1.6.2", "jade": "~1.11.0", "jsonwebtoken": "^8.5.1", "mongoose": "^5.9.4", "morgan": "~1.9.0", "passport": "^0.4.1", "passport-jwt": "^4.0.0", "passport-local": "^1.0.0", "passport-local-mongoose": "^6.0.1", "session-file-store": "^1.4.0", "uuid": "^7.0.2" }, "devDependencies": { "nodemon": "^2.0.2" } }我必须每次都从终端显式终止服务器,这不是最佳解决方案. 我尝试了几种方法,但是都没有用.甚至在nodemon GitHub问题页面上发现了一些问题,但是我也找不到任何东西.
I've to explicitly kill the server from the terminal every time, which is not the optimal solution. I tried several things, but none are working. Even found some issue in nodemon GitHub issue page, but there also I couldn't find anything.
即使服务器正在关闭服务器,我也要添加 lsof -i:5000 的输出-节点31625 rishav 20u IPv6 5300049 0t0 TCP *:5000(LISTEN )
I'm also adding the output of lsof -i:5000, even if server I'm closing the server - node 31625 rishav 20u IPv6 5300049 0t0 TCP *:5000 (LISTEN)
推荐答案我遇到了同样的情况.如果您使用的是Visual Studio Code,请检查您的终端.您可能还有其他已经在运行节点服务器的终端实例.
I had the same situation. If you are using Visual Studio Code, check your terminals. You might have other instances of the terminal that is already running your node server.
更多推荐
Nodemon:错误:监听EADDRINUSE:地址已在使用::: 5000
发布评论