0

What happened was, I was fiddling with node, but when I killed node with ctrl+c, and started it up again i got an EADDRINUSE error:

EADDRINUSE, Address already in use

So I followed the advise given for killing :3000 using its PID: Kill localhost:3000 process from Windows command line

So, now when I run netstat -a -o, I can't find port 3000. Which makes sense, I killed it. But how do I get it up and running again, and set up so that port 3000 is listened to?!

Yeah, I've tried starting my server again, but nothing happens. Literally no response. It worked before.

Version: $ node -v v4.2.2

Yes, I am a major n00b, let's get that out of the way. Thanks.

NODE JS CODE:

'use strict' 
var port = 3000;
var express = require('express'); 
var app = express(); 
app.get('/', function(req,res){ res.send("I love treehosue"); });
app.listen(port, function(){ process.exit() console.log("server running on "+port); });
Community
  • 1
  • 1
Hanky
  • 1
  • 2
  • It had probably been in TIME_WAIT state which had expired by the time you ran `netstat`. It only lasts a couple of minutes. Just restart the server now. – user207421 Feb 10 '16 at 01:30
  • I'd suggest you show us exactly what your netstat shows you (paste it into the question) and show us the code that initializes your server to run on a particular port (paste that into the question too). One of the other is not as you think. – jfriend00 Feb 10 '16 at 01:30
  • https://drive.google.com/file/d/0B8IWteknUyMYVmhxS211NUhzVkU/view?usp=sharing – Hanky Feb 10 '16 at 01:43
  • 1
    @HenricHankyGustafsson Don't post code in comments. You can see for yourself that the result is completely illegible. Edit it into your question. – user207421 Feb 10 '16 at 01:47
  • Ok :) Edited now, see post above ^ – Hanky Feb 10 '16 at 01:51

2 Answers2

1

I had the same problem. The way I solved this issue was by simply erasing everything and starting anew. But instead of running (npm init --yes), I only ran npm init and manually filled the empty fields such as repo, etc. Hope this helps to everyone even though this question was posted in 2016.

JS11
  • 21
  • 4
0

The steps you have taken to kill the process are correct.

The problem you are experiencing is likely coming from unexpectedly terminating the application. The socket is missing a proper close operation and the OS blocks the port for a certain timeout.

From personal experience, on a linux system this can be somethink around 30sec.

Chris
  • 2,111
  • 3
  • 22
  • 45
  • 2*MSL = four minutes actually, unless someone has messed with the MSL. – user207421 Feb 10 '16 at 01:36
  • EJP , you are refering to linux? – Chris Feb 10 '16 at 01:37
  • I'm referring to RFC 793. – user207421 Feb 10 '16 at 01:37
  • Well, I'm a windows user, and I've been troubleshooting for hrs and have restarted my computer (the idiot fix lol). Any advice? – Hanky Feb 10 '16 at 01:47
  • @Hanky My first comment under your question contains advice. What happened when you tried it? – user207421 Feb 10 '16 at 01:51
  • Yeah, I've tried starting my server again, but nothing happens. Literally no response. – Hanky Feb 10 '16 at 01:57
  • @Hanky, have you already checked this question here: http://stackoverflow.com/questions/4075287/node-express-eaddrinuse-address-already-in-use-kill-server ? sounds like your problem, and someone gave a solution for windows: taskkill /F /IM node.exe – Chris Feb 10 '16 at 02:01
  • Yeah, checked it out prior to doing a kill with netstat. Have not tried taskkill /F /IM node.exe though, I'll keep ya posted. – Hanky Feb 10 '16 at 02:04
  • Can't find the process. Error msg is in swedish, so won't do you no good, but that's the jest of it all. – Hanky Feb 10 '16 at 02:09
  • and what if you have the node app running and the terminating it via taskkill /F /IM node.exe? – Chris Feb 10 '16 at 02:11
  • It was running, I made a small error, now I've killed the task & it doesn't show up in tasklist. Going to start node again... Well, node app.js still does nothing. Strange. – Hanky Feb 10 '16 at 02:12
  • just thinking out loud now : are you using some ide? Just for testing reasons you could download the trial version of webstorm (https://www.jetbrains.com/webstorm/). I've never had the problem you are describing, when using webstorm. You can stop and instantly restart the app – Chris Feb 10 '16 at 02:17
  • Not using webstorm, using sublime for editing, git bash to navigate into dirs/create dirs/ create files, install and run node. And running node.exe in the background. – Hanky Feb 10 '16 at 02:21
  • If you are killing and restarting node for the sake of having your development changes take effect, you might want to consider `nodemon`: https://github.com/remy/nodemon. This will automatically detect changes and restart the server for you. It works on Windows as well as Linux. – Rai Feb 10 '16 at 02:26
  • I was using nodemon prior to this issue :) but now neither node app.js or nodemon app.js does anything. It's supposed to listen to :3000 but since that port isn't listening, or even listed, I guess it's like it doesn't know what to do or something. – Hanky Feb 10 '16 at 02:45
  • 'Literally no response' is not a repetition of the original problem, which was a bind error: `EADDRINUSE, Address already in use`. Unclear what you're now asking. NB My advice should have been read as restarting your *application.` – user207421 Feb 10 '16 at 03:21