Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 305 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nodemon: Error: listen EADDRINUSE: address already in use :::5000

#1
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**

<!-- language: lang-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"
}
}

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.

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)**
Reply

#2
Your port is used somewhere else. Most likely, you forgot to stop previous instance of node before running new one.
Reply

#3
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.
Reply

#4
How I solved it, since I was not running anything on that port and it still gave me the error. Kill node to clear is cache with:

`pkill nodejs` or `pkill node` depending on OS/version

Could also use `fuser -k 8000/tcp` to kill any port immediately. (linux)
Reply

#5
If you are working on a file > saved it > then got the errr try this:

> ReSave the file you made changes on once or twice more and the problem goes away for
> me every time.

Save the file once:
```
Error: listen EADDRINUSE: address already in use :::5000
...
[nodemon] app crashed - waiting for file changes before starting...
```
Save the file a seconds time (without making changes) [command]+ s
```
[nodemon] restarting due to changes...
[nodemon] starting `node app.js`
Server is running on port: 5000
```
[![enter image description here][1]][1]


[1]:
Reply

#6
I'm experiencing the same with vscode. Rapid "double save" cmd-c works most of times.
Reply

#7
I got:

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

**I was trying to look for the process listening to port 8000
and had no luck - there were none** (`sudo netstat -nlp | grep 8000` ).

It turned out **I had `app.listen(8000)` written twice** in my script.

My assumption is that the interference was happening only in a short time when trying to run the script, so looking for processes listening to the port before and after error didn't show any.
Reply

#8
I used this to fix the same problem

process.once('SIGUSR2',
function () {
process.kill(process.pid, 'SIGUSR2');
}
);

[To see links please register here]

Controlling shutdown of your script
Reply

#9
I think that error happens to me when I shut down the server's terminal without turning off nodemon beforehand.

Then, usually the next day, nodemon starts acting weird.

**How I solved it:**
What I noticed is that when running ***ps -fp $(grep -u my_username)***, I got several instances of nodemon up and running. So I did ***pkill -f nodemon***, which killed all nodemon instances, and then relaunched nodemon and all was good again in the wonderful realm of my Linux server.
Reply

#10
My solution is simple
1. suppose ex:- current port is 4000 then change it to 4001.

trust me it will work don't look for a big solution. if the problem with the existing port number change that to different as long as your application works no problem
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through