0
votes

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); });
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
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
@HenricHankyGustafsson Don't post code in comments. You can see for yourself that the result is completely illegible. Edit it into your question.user207421
Ok :) Edited now, see post above ^Hanky

2 Answers

1
votes

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.

0
votes

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.