Nodejs application Error: bind EADDRINUSE when use pm2 deploy
Solution 1
I don't know the port used by your application. It depends on your code. In this example, I will assume the port is 3000
.
You need to verify if the port is already took on your system. To do that:
- On linux:
sudo netstat -nltp | grep 3000
- On OSX:
sudo lsof -i -P | grep 3000
If you have a result, you need to kill the process (kill <pid>
).
You should check if pm2 list
returns 0 process. In addition, when you do a pm2 stopAll
, the socket is not released. Don't forget to do a pm2 kill
to be sure the daemon is killed.
$ pm2 kill
Daemon killed
Solution 2
OS X
Cmd+Space -> enter: Activity Monitor -> find your app and terminate it.
Related videos on Youtube
Comments
-
lidashuang almost 4 years
Express application deploy with pm2
database is mongodb
when run app with command:
NODE_ENV=production pm2 start app.js -i max
aften has Error: bind EADDRINUSE, this is logs, when error,
[app err (l0)] js:1073:26 [app err (l1)] at Object.30:1 (cluster.js:587:5) [app err (l2)] at handleResponse (cluster.js:171:41) [app err (l3)] at respond (cluster.js:192:5) [app err (l4)] at handleMessage (cluster.js:202:5) [app err (l5)] at process.EventEmitter.emit (events.js:117:20) [app err (l6)] at handleMessage (child_process.js:318:10) [app err (l7)] at child_process.js:392:7 [app err (l8)] at process.handleConversion.net.Native.got (child_process.js:91:7)Error: bind EADDRINUSE [app err (l9)] at errnoException (net.js:901:11) [app err (l10)] at net.js:1073:26 [app err (l11)] at Object.31:1 (cluster.js:587:5) [app err (l12)] at handleResponse (cluster.js:171:41) [app err (l13)] at respond (cluster.js:192:5) [app err (l14)] at handleMessage (cluster.js:202:5) [app err (l15)] at process.EventEmitter.emit (events.js:117:20) [app err (l16)] at handleMessage (child_process.js:318:10) [app err (l17)] at child_process.js:392:7 [app err (l18)] at process.handleConversion.net.Native.got (child_process.js:91:7)
This causes app is slow, How to solve this problem, thanks very much
-
Marcello de Sales about 10 yearsI get this same error without having any process listed... "pm2 delete all", then "pm2 start app.js", and I still get that error... "sudo netstat -nltp | grep 3000" continues to show nothing...
-
Ryan-Neal Mes over 7 yearsI ran into this problem as well. It seems when you exit pm2 using
ctrl+c
it does not actually kill the node process (if you were running a node process). Using the solution above allowed me to find my server and kill it. I would have thought pm2 does this gracefully, but it doesn't. Note I was using an express server. -
yussan about 7 yearsit's work very well, i do it on my production, thanks to save my life
-
Bill Gardner about 3 yearsSix years later, this saved my butt today. Killing the pm2 processes was the key to my errors.
-
Sandro Munda about 3 yearsGlad to hear that it helps 6 years later Bill 😅