How to stop app that node.js express 'npm start'
All the other solutions here are OS dependent. An independent solution for any OS uses socket.io as follows.
package.json has two scripts:
server.js — Your usual express stuff lives here
server.stop.js
Test it out
npm start (to start your server as usual)
npm stop (this will now stop your running server)
The above code has not been tested (it is a cut down version of my code, my code does work) but hopefully it works as is. Either way, it provides the general direction to take if you want to use socket.io to stop your server.
Yes, npm provides for a stop script too:
npm help npm-scripts
prestop, stop, poststop: Run by the npm stop command.
Set one of the above in your package.json, and then use npm stop
npm help npm-stop
You can make this really simple if you set in app.js ,
And, then in scripts.json,
That said, if this was me, I’d be using pm2 or something the automatically handled this on the basis of a git push.
How to Stop a React App from Running in Windows
Let’s say you are running a React app, which you started using npm start:

It is running in a browser, but closing the browser does not stop the app:

To stop this from running, in the command prompt, type CTRL-C. You will get the prompt to Terminate batch job:

Type Y and the app will stop running:

You can now run npm start again if you want to relaunch the app.
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET’S KEEP LEARNING TOGETHER.

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.
How to stop running npm process on the terminal shell
Unlike with starting a npm process where you need to run the npm start or npm run serve command, stopping a running npm process doesn’t require a command.
You can stop any running npm process with CTRL + C (Windows/Linux/Mac)
For example, suppose you have a running Vue local server as follows:
You need to select the running shell window, then press CTRL + C to stop the process.
You should see a new line available in your shell, indicating that you can run another command from it:
Alternatively, you can close the shell window to stop the running process immediately.
This can be useful when the running process is lagging and pressing CTRL + C isn’t working.
The same method will work no matter what project you are running (Vue, React, Express, etc.)
People new to npm-based projects usually thought they need to create a stop script in the scripts object:
But while you can define a stop script to run with the npm stop command, that command doesn’t have any special meaning in npm.
It’s just another command you can run using npm, but it doesn’t stop the running server just because the name is npm stop .
To stop a running npm process, press CTRL + C or close the shell window.
Here’s a short video showing the keystrokes:
Your browser does not support the video tag.
And that’s how you stop a running npm process on the terminal.
Learn JavaScript for Beginners
Get the JS Basics Handbook, understand how JavaScript works and be a confident software developer.
A practical and fun way to learn JavaScript and build an application using Node.js.
About
Hello! This website is dedicated to help you learn tech and data science skills with its step-by-step, beginner-friendly tutorials.
Learn statistics, JavaScript and other programming languages using clear examples written for people.
How to stop app that node.js express 'npm start'
You build node.js app with express v4.x then start your app by npm start. My question is how to stop the app? Is there npm stop?
EDIT to include the error when implement npm stop
16 Answers 16
Yes, npm provides for a stop script too:
npm help npm-scripts
prestop, stop, poststop: Run by the npm stop command.
Set one of the above in your package.json, and then use npm stop
npm help npm-stop
You can make this really simple if you set in app.js ,
And, then in scripts.json,
That said, if this was me, I’d be using pm2 or something the automatically handled this on the basis of a git push.
All the other solutions here are OS dependent. An independent solution for any OS uses socket.io as follows.
package.json has two scripts:
server.js — Your usual express stuff lives here
server.stop.js
Test it out
npm start (to start your server as usual)
npm stop (this will now stop your running server)
The above code has not been tested (it is a cut down version of my code, my code does work) but hopefully it works as is. Either way, it provides the general direction to take if you want to use socket.io to stop your server.
On MAC OS X(/BSD): you can try to use the lsof (list open files) command

![]()
When I tried the suggested solution I realized that my app name was truncated. I read up on process.title in the nodejs documentation (https://nodejs.org/docs/latest/api/process.html#process_process_title) and it says
On Linux and OS X, it’s limited to the size of the binary name plus the length of the command line arguments because it overwrites the argv memory.
My app does not use any arguments, so I can add this line of code to my app.js
and then add these few lines to my package.json file
to use really long process names. npm start and npm stop work, of course npm stop will always terminate all running processes, but that is ok for me.
Check with netstat -nptl all processes
And it simply kills the process by the PID reference. In my case I want to stop the 6231/nodejs so I execute the following command:
![]()
This is a mintty version problem alternatively use cmd. To kill server process just run this command:
![]()
If you’ve already tried ctrl + c and it still doesn’t work, you might want to try this. This has worked for me.
Run command-line as an Administrator. Then run the command below to find the processID (PID) you want to kill. Type your port number in <yourPortNumber>
netstat -ano | findstr :<yourPortNumber>

Then you execute this command after you have identified the PID.
taskkill /PID <typeYourPIDhere> /F

simplified version. Simple copy paste with the port to kill ex.5000
![]()
For windows machine (I’m on windows 10), if CTRL + C (Cancel/Abort) Command on cli doesn’t work, and the screen shows up like this:

Try to hit ENTER first (or any key would do) and then CTRL + C and the current process would ask if you want to terminate the batch job:

Perhaps CTRL+C only terminates the parent process while npm start runs with other child processes. Quite unsure why you have to hit that extra key though prior to CTRL+ C, but it works better than having to close the command line and start again.
![]()
Here’s another solution that mixes ideas from the previous answers. It takes the «kill process» approach while addressing the concern about platform independence.
It relies on the tree-kill package to handle killing the server process tree. I found killing the entire process tree necessary in my projects because some tools (e.g. babel-node ) spawn child processes. If you only need to kill a single process, you can replace tree-kill with the built-in process.kill() method.
The solution follows (the first two arguments to spawn() should be modified to reflect the specific recipe for running your server):