1

I am running a simple node js server on my Mac. I also have mamp installed. Just FYI.I am able to go to localhost:8888 just fine and preview the web page. However, in my server.js file, if I include the host as a parameter to the server.listen function like so

server.listen(127.0.0.1, 8888, function(){
        console.log('Server running');
})

I get the following error in my terminal.

Error: listen EADDRINUSE 127.0.0.1
    at Object._errnoException (util.js:992:11)
    at _exceptionWithHostPort (util.js:1014:20)
    at Server.setupListenHandle [as _listen2] (net.js:1338:19)
    at listenInCluster (net.js:1396:12)
    at Server.listen (net.js:1491:5)
    at Object.<anonymous> (/Users/username/Desktop/nodeServer/server.js:12:8)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
Users-Mac-Pro:nodeServer user$ 

If I just have

server.listen(8888, function(){
        console.log('Server running');
})

everything works fine. Does this have anything to do with the fact that I have mamp installed? Just want to understand why one works and the other doesn't.

1
  • Nothing is running on port 8888. I have tried numerous ports and all don't work. I think it may have something to do with my apache web config. Commented Aug 31, 2018 at 17:45

3 Answers 3

2

Try putting your host after port as following

server.listen(8888, '127.0.0.1', function() {
console.log('Server running');
})

app.listen documentation

app.listen([port[, host[, backlog]]][, callback])
Sign up to request clarification or add additional context in comments.

1 Comment

This was the issue. I had to reverse the order of the parameters. Host needed to go after the port. Thank you so much!
0

Some other process might have been using 8888 port. You can either kill that process or use someother port for your nodejs server.

To get the process id of the process using port 8888, use

lsof -i tcp:8888

and kill the process using

kill -9 <pid>

Hope this helps.

Comments

0

Probably you're currently running your server in that port. Try with:

killall node

1 Comment

I just ran that command in the terminal but there is no process running on port 8888. But I am still getting this error. Any clues?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.