-1

While trying to run node server using node server.js, I get the error to listen EADDRINUSE :::4002. I get the process listening on port 4002 by the command: sudo lsof -i :4002. After that I try to kill the process using kill -9 . The problem is when I run sudo lsof -i :4002 command again after killing the process, I see the node process running again with a different proces id.

The node server was started by a different user and I am trying to kill it with another user.

Ravi Kukreja
  • 587
  • 1
  • 6
  • 17

3 Answers3

2

As we've discussed that the process is managed and automatically restarted by pm2, you'll have to stop the pm2 process instead of just killing the node process. To do that, run the following commands

sudo -u <user who is running the process> pm2 list

You'll now find all processes the given user has started. From here, take the id(s) of the process you want to stop, then run (to stop a single process)

sudo -u <user who is running the process> pm2 stop <id>

or to simply stop them all

sudo -u <user who is running the process> pm2 stop all

Note that sudo -u is only needed because the processes are run by another user. If you want to stop a process your current user has created, omit the sudo -u <user> part

baao
  • 62,535
  • 14
  • 113
  • 168
1

Try this cmd in the terminal to kill all node process :

killall node
1
  1. 'netstat -nptl' to see all the processes
  2. kill -9 3887 (E.g Node is running over 3887/node)
Sushant Magoo
  • 314
  • 3
  • 12
  • The process seems to be automatically restarted. How does this answer solve the problem at hand? – – baao Jun 29 '18 at 16:02
  • As I can see your above comments and understand your problem, you want to remove pm2 scripts on start. To automatically start all nodejs processes on startup, command is `pm2 startup` and exactly opposite command is `pm2 unstartup`, to remove all nodejs startup processes, which is what i think you are asking for. – Sushant Magoo Jun 29 '18 at 16:16