Maxy.fr

Finding and Stopping a Lingering Node.js Instance

If you've been playing around with Node.js, you've probably run a Node.js file and left it running in the background. You may be accustomed to using the shortcut ctrl + c (cmd + c) or ctrl + z (cmd + z) to suspend or stop its process. However, if you've closed the terminal with your SSH connection in the meantime, you won't find your session where you had launched your Node.js file. Nevertheless, it remains active.

To find and stop the corresponding process, here are the commands to use:

ps aux | grep node

These two commands allow you to display all active processes on the server with the search criterion "node."

You will get one or more lines like this for each of the still-active processes:

root     19231   0.2   3.6 704620 74856 pts/0     Sl+   Nov10   0:05 node yourFile.js

 

Take note of the first number, which is the process ID (e.g., 19231), and execute the following command to stop this specific process:

kill -9 ProcessID

Categories : Node.JS

By Guillaume - 11/11/2016 at 12:10 am

Shar this article :

Similar articles

Automatically Start Node.js on Server Boot

If you've ever created programs using Node.js, you've probably encountered this issue: Node.js scripts don't automatically restart when you reboot your server. Therefore, you need to manually reconnect to restart them, which can be quite inconvenient. Here's a small shell script that allows you to...