I have a node app that has to run on localhost:3000 but my mac keeps saying that something is running on port 3000. When I run netstat or lsof and check for running programs on port 3000 I get nothing. When I was ran yarn start or npm run and it prompted to run on a different port node was able to get the app running, however it is a NECESSITY that it run at localhost:3000
let me preface this fix to say that I develop on many different platforms and systems on my mac. Most of my systems are LAMP projects, either custom PHP or Wordpress or Laravel and I use MAMP almost exclusively for building and developing on those code bases. I used to run my php projects without MAMP a few years ago, mostly using Homebrew for deving, this required manually editing my hosts file - but since moving to MAMP my need for editing my hosts file is gone - MAMP handles it. Until now.
So why is my port blocked for localhost? Why isn't 3000 available? Why can't node serve to 3000? The answer for me was in the hosts file.
Open your dev boxes hosts file - mine was at /etc/hosts
sudo nano /etc/hosts
My file had an entry that looked like this
27.0.0.1 localhost
Wait - shouldn't there be a '1' there?
So I added the 1 and saved (ctrl x - and yes to save)
127.0.0.1 localhost
and then started my app
yarn start
and it worked. Localhost wasn't able to resolve and in the end that was causing the port to look occupied. UGH