Node.js Port 3000 already in use but it actually isn't?

user2573690 picture user2573690 · Sep 5, 2016 · Viewed 218.6k times · Source

I have been working with a node.js project for a few weeks and it has been working great. Usually, I use npm start to run my app and view it in a browser on localhost, port 3000.

Today, I started to get the following error while using npm start:

Server started on port 3000                                                                                                                                                                                         
Port 3000 is already in use 

I have checked the resource monitor and I have no other process running on port 3000. Why would I be getting this error message?

In my app.js I have the following code to set the port...is this incorrect? It worked fine before so I'm not sure what I am doing wrong.

// Set Port
app.set('port', (process.env.PORT || 3000));
app.listen(app.get('port'), function() {
    console.log('Server started on port '+app.get('port'));
});

Thanks for the help!


EDIT:

I have tried running netstat and TCPView to check what process is using the port, but there is nothing using that port. I also tried restarting my laptop but I still get the same error.

Answer

Animesh Singh picture Animesh Singh · Jul 16, 2017

You can search on how to kill that process.

For Linux/Mac OS search (sudo) run this in the terminal:

$ lsof -i tcp:3000
$ kill -9 PID

On Windows:

netstat -ano | findstr :3000
tskill typeyourPIDhere 

change tskill for taskkill in git bash