a blog for those who code

Saturday 19 September 2015

How to solve nodejs Error: listen EADDRINUSE

In this post we are going to discuss about how to solve Node.js error: listen EADDRINUSE. EADDRINUSE actually means that the port number which you are binding to the server using listen() is already in use.

Lets say you are creating a http server using the below code where you are binding the port number 8080 to the server.

var http = require('http');
var requestListener = function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello You\n');
}
var server = http.createServer(requestListener);
server.listen(8080);

If any application is already running on 8080 then you will get the below error (Error: listen EADDRINUSE).

You can check using netstat -an that is there any process running on 8080 or not. If there will be any process running on 8080 you will see something like below when you run command netstat -an in Command Prompt.


To solve this error either you start your node server on another port or close the program using that port. So you can kill the 8080 process or start server on 8081.

Please Like and Share the CodingDefined Blog, if you find it interesting and helpful.

3 comments:

  1. I checked using netstat -an but no other process is using port number 3000. And I am still getting the error: Listen EADDRINUSE 127.0.0.1:3000. What can I do?

    ReplyDelete
    Replies
    1. I will recommend you to use different port in your node application, might be some other processes are using this port.

      Delete
  2. i used netstat -an
    and my problem is solve
    thanks

    ReplyDelete