Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

node js listen EADDRINUSE error for simple httpserver

node js listen EADDRINUSE error for simple httpserver


I have simple Node js http server.

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");

If I run

node basicserver.js 

I get

        throw e; // process.nextTick error, or 'error' event on first tick
Error: listen EADDRINUSE
    at errnoException (net.js:642:11)
    at Array.0 (net.js:743:26)
    at EventEmitter._tickCallback (node.js:192:40)

I have seen this post, but that post seems to be specific to TCP server and not http server. Could anyone please help.

Problem courtesy of: riship89


The port you are listening to is already being listened by another process. In this case I got a feeling that it is your self. You can do a ps aux | grep node and then using kill kill your node process. Beside that you can also try another port.


In case if you want to find which process is listening, you can use netstat -lpn ( -l is to find out the listening ports, -p is to include the process name and pid, -n is to not to resolve host names, or else it will be slow), to find the processes that are listening on different ports. If there was too many, you can do netstat -lnp | grep :8888.

Also can use, fuser 8888/tcp, which will show you the process pid and also adding -k will kill the process, fastest way ever.

I realized this two commands only work in linux.

Solution courtesy of: Farid Nouri Neshat


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

node js listen EADDRINUSE error for simple httpserver


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription