Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stopping node.js process on Mac

I have a node.js application that uses some socket ports. Sometimes, when I exit the application with Ctrl + C, some kind of node process is left running, still allocating the socket ports. Thus, I cannot restart my application, since it fails to open those ports. When I look the situation with ps, I get the following response:

$ ps

PID TTY           TIME CMD

40454 ttys000    0:00.11 -bash

41643 ttys001    0:00.00 (node)

41741 ttys001    0:00.00 (node)

Trying kill -9 41643 doesn't kill the process. Is it a some kind of unkillable zombie? How can I get rid of those (node)-things blocking my tcp ports?

like image 699
user2516371 Avatar asked Sep 05 '13 08:09

user2516371


People also ask

How do I stop a node process on Mac?

Ctrl+Z suspends it, which means it can still be running. Ctrl+C will actually kill it. Hope it is helpfull!! To know more about it, enroll in Node.

How do I end a node JS process?

Method 1: Using ctrl+C key: When running a program of NodeJS in the console, you can close it with ctrl+C directly from the console with changing the code shown below: Method 2: Using process. exit() Function: This function tells Node. js to end the process which is running at the same time with an exit code.

How do I stop a NPM process?

To stop a running npm process, press CTRL + C or close the shell window.

How do I stop a node JS instance?

exit() in your application causes the NodeJS instance to close. killall node in bash would kill all NodeJS instances running on your machine.


2 Answers

I'm not a MAC user, but here is what I use to kill all the available node processes (under linux):

sudo killall -9 node
like image 137
Krasimir Avatar answered Oct 05 '22 23:10

Krasimir


On macOS, it's simply:

sudo killall -9 node

For a lot of the times, sudo is overkill, but in your case, it looks like you might want to try sudo.

like image 32
Sal Rahman Avatar answered Oct 05 '22 23:10

Sal Rahman