Stopping All Instances of Node.js Server

Introduction

When working with Node.js, you may need to stop all running instances of a Node.js server, especially if they are consuming system resources or causing conflicts. This guide provides step-by-step methods to stop all Node.js server instances on different operating systems.

Method 1: Using Process ID (PID)

Step 1: Identify Running Node.js Processes

Run the following command to list all running Node.js processes:
ps aux | grep node
This will display a list of Node.js processes with their process IDs (PIDs).

Step 2: Kill the Processes

Once you have identified the PIDs, use the following command to terminate them:
kill -9
Replace with the actual process ID. If there are multiple processes, run:
kill -9 $(pgrep node)

Method 2: Using pkill Command (Linux/macOS)

To stop all Node.js instances at once, you can use:
pkill -9 node
This command forcefully stops all running Node.js processes.

Method 3: Using taskkill (Windows)

Step 1: Identify Running Node.js Processes

Run the following command in the Command Prompt (cmd):
tasklist | findstr node
This will list all running Node.js processes with their PIDs.

Step 2: Kill the Processes

Use the following command to terminate all Node.js instances:
taskkill /F /IM node.exe

Method 4: Stopping a Node.js Server Started with nohup or &

If the server was started using:
nohup node server.js &

To stop it, find its PID using:
ps aux | grep node

Then terminate it using:
kill -9

Method 5: Using pm2 (If Running with Process Manager)

If the Node.js server is managed using pm2, stop all instances with:
pm2 stop all

To completely kill all instances and remove them from pm2:
pm2 delete all

Conclusion

Stopping all instances of a Node.js server depends on how it was started. Using pkill, kill, taskkill, or pm2 stop ensures that all running instances are properly terminated. Choose the method that suits your operating system and process management approach.

Need Help With Node Development?

Work with our skilled Node developers to accelerate your project and boost its performance.

Hire Node.js Developers

Support On Demand!

Related Q&A