How do i overcome EADDRESS already in use in PM2

Viewed 68

I am running a node js server on aws EC2 instance

when i do node server.js its working but when i start the server using pm2 i am getting code: 'EADDRINUSE',

after installing pm2 can't even use node server.js it also says EADDRINUSE, so to rerun it i have to uninstall the pm2 and stop the node process that runs port 3000, but as soon as i install pm2 the port 3000 is becoming unavailable

root       47971  0.7  2.7 647924 55712 ?        Ssl  11:20   0:00 node /home/ubuntu/kanaswap-name-service/server.js

the above process runs automatically when i install pm2 , i cant even kill that process

when i run node server.js enter image description here

pm2 list enter image description here

process that runs on port 3000 enter image description here

even after killing the process it runs automatically,

1 Answers

this happens because everytime you start pm2 it says that a service on that port alredy running try changing the port no or you can kill the process if you are using linux

here is the command for kill the process in linux this is for getting PID

lsof -i:<port no.>

after that you may find that result

node    14977 USER   22u  IPv4 191006      0t0  TCP *:3004 (LISTEN)

after that run this

kill 9 <port no.>
Related