You had run another server use the same port like 8080.
Maybe you had run node app
in other shell, Please close it and run again.
You can check PORT no. is available or not using
netstat -tulnp | grep <port no>
Alternatively, you can use lsof:
lsof -i :<port no>
We do get similar error when we sometimes run our express app. We have to follow the same in that case. We need to check if its running in any terminal. If you want to find and kill process, follow these steps:
OR
Use a single command to close all the running node processes.
ps aux | awk '/node/{print $2}' | xargs kill -9
An instance is probably still running. This will fix it.
killall node
Update: This command will only work on Linux/Ubuntu & Mac.
If you're on Linux, this problem can also occur if Nodejs is not running as root.
Change from this:
nodejs /path/to/script.js
To this:
sudo nodejs /path/to/script.js
Just happened to me and none of the other suggestions here fixed it. Luckily I remembered the script was working the other day when running as root. Hope this helps someone!
Disclaimer: This probably isn't the best solution for a production environment. Starting your service as root may introduce some security holes to your server/application. In my case, this was a solution for a local service, but I'd encourage others to spend some more time trying to isolate the cause.
This is because the port you are using to run the script is already in use. You have to stop all other nodes which are using that post. for that, you can check all node by
ps -e
OR for node process only use ps -ef | grep node
This will give you the list of all node process with id
to Kill all node process
sudo killall -9 node
Or for the specific id sudo kill -9 id
I fixed the bug by changing the port which was
app.set('port', process.env.PORT || 3000);<br>
and changed to:
app.set('port', process.env.PORT || 8080);<br>
The port Node is trying to use can be already used by another program. In my case it was ntop, which I had recently installed. I had to open http://localhost:3000/ in a browser to realize it. Another way to find the process is given here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With