1

I am using node 8.11.1 along with angular 6, locally on windows 10. In my node app.js I have

//SERVER LISTEN
app.listen(3000, ()=>{
  console.log('Server running on port 3000');
});

at the bottom and I run my node using nodemon.

I did not installed any program recently, and node/angular worked perfectly.

I did some editing on a query code in node, some minor editing and then copied some files to an external drive. I did not remove the files, I copied them, so they are still on my laptop too, I can see them. These are the last steps I can recall.

And yet, I do nodemon, now I get

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::3000

What happened ? Is there an explanation ? How can I get node to run on port 3000 again? Thanks

slevin
  • 3,640
  • 16
  • 58
  • 106

2 Answers2

3

Make sure that no other application is using port 3000. Try specifying a different port id

This error usually occurs when the port is already in use and your application is trying to run on the same port,

    //SERVER LISTEN
app.listen(3001, ()=>{
  console.log('Server running on port 3001');
});
Hiteshdua1
  • 1,770
  • 15
  • 26
  • But it was working on port 3000 all this time. And I did not installed anything new. Do I have a virus on my laptop? Hey, by the way, any idea on how to check what is listening on port 3000 ? Thanks – slevin Jul 31 '18 at 22:33
  • To confirm, change port no to say `3001` as i have updated in the answer. Nothing like a virus I would say. Maybe one of your previous application is running which is also using the same port. – Hiteshdua1 Jul 31 '18 at 22:34
  • I dont have any other node apps, just extra angular apps on the same node. Anyway I tried with port 3001 and works fine. I just have to change some API URLs now, but node runs OK with the new port. – slevin Jul 31 '18 at 22:40
  • I guess then the port is being used, i'll say log out of your user session and then log back in if you cant really identify the which application is using that port. It should work I guess. And do upvote/ accept answer if the solution works for you pal. – Hiteshdua1 Jul 31 '18 at 22:46
  • netstat -aon | findstr '[port_number]' to check which application is using that port – Hiteshdua1 Jul 31 '18 at 22:51
  • All the options told by all of you is not working.When I restart the PC then port Issue get solved. Suppose If we can't change the port how this get solved ? – Prashant Gupta Aug 01 '18 at 03:36
  • I believe you have to find the application which is using the port, using command specified above for windows and kill it. [That is what really happened when you restarted the PC] – Hiteshdua1 Aug 01 '18 at 05:59
1

Try to find what is running on that port. You can search online on how to find what is running on your windows system. This post here can help. In fact I used the below command which I got from this post and it clearly showed me what was running on that port.

for /f "tokens=5" %a in ('netstat -aon ^| findstr <port>') do tasklist /FI "PID eq %a"

Get the PID from there, and you can use the next command to kill that process. Hope this helps.

Taskkill /PID <pid> /F
xan_z
  • 197
  • 8