Error: listen EADDRINUSE with NodeJS Server

EADDRINUSE indicates the port number that listen() is attempting to bind the server to is already in use.

Sometimes, even though you have hit Control C a few times. Somehow nodejs is still running. My guess is that there are lingering processes from a faulty termination for whatever reason.

How to fix Error: listen EADDRINUSE

If you are getting an error that looks like this:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1039:14)
    at listen (net.js:1061:10)
    at Server.listen (net.js:1135:5)
    at EventEmitter.listen (/home/pkl/diamond/glcodeapi/node_modules/express/lib/application.js:617:24)
    at Object.<anonymous> (/home/pkl/diamond/glcodeapi/app.js:62:5)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

Then from the terminal on the nodejs server use prgrep to find the process id.

$> pgrep nodejs
1119

Then kill the nodejs process occupying port 3000 like this

kill  1119

Now that port 3000 is released you should be good to start you nodejs app

nodejs app.js

Leave a Reply

Your email address will not be published. Required fields are marked *