How to stop npm serve
Asked Answered
P

5

35

I've build React Apps:

npm run build

and installed globally serve package:

npm install -g serve

and run it:

serve -s build

How do I stop it?

I've tried serve help but it doesn't show any stop option

Options:

-a, --auth      Serve behind basic auth
-c, --cache     Time in milliseconds for caching files in the browser
-n, --clipless  Don't copy address to clipboard (disabled by default)
-C, --cors      Setup * CORS headers to allow requests from any origin (disabled by default)
-h, --help      Output usage information
-i, --ignore    Files and directories to ignore
-o, --open      Open local address in browser (disabled by default)
-p, --port <n>  Port to listen on (defaults to 5000)
-S, --silent    Don't log anything to the console
-s, --single    Serve single page applications (sets `-c` to 1 day)
-u, --unzipped  Disable GZIP compression
-v, --version   Output the version number
Pablopabon answered 27/7, 2017 at 9:36 Comment(0)
D
46

You can stop the process on the console like any other process: Ctrl + c.

See https://superuser.com/questions/103909/how-to-stop-a-process-in-terminal

Diopside answered 27/7, 2017 at 9:39 Comment(8)
but when I visit localhost:5000, the App is still running. Shouldn't it stop running as well when I press Ctrl + c ?Pablopabon
Yes it should stop, if you press Ctrl + c if the process is in the foreground. Is it? You can also try to kill the process. Search for the process nummer (e.g. ps aux | grep serve) and pkill <id>. I tested it locally and everyhting works fine for me. Perhaps your browser is somehow serving the page from cache.Diopside
@Pablopabon does the app still load when you refresh using Ctrl + F5?Methacrylate
@MarcScheib oh right.. looks like it's all about the cache! Literally spent hours on this and looks like no other has got the same problem, turns out pretty simple.. thanks.Pablopabon
in my case is not cache. another option?Oneself
Server don't stop with Ctrl+C. I can continue coding and every time I save it compile and update the browser. I close every program and then open the browser and go to localhost:3000. The app runs and if I open the editor I can go on and code, save and it updates... I'm on Windows. If I try npm start it gives me the feedback that something is already running on port 3000. I have to restart Windows.Affectation
it does not work. I am using VS Code terminal. ThanksFenestrated
Thanks @MarcScheib the browser was serving from cache upon clearing it, gone.Sienna
R
12

I had the same problem using serve to serve the production build of my react app (built from create-react-app).

I was able to finally kill it by using serve again somewhere else on my filesystem (like my home directory and then killing it with: Ctrl + c.

You can do something like this to kill your react app being served by serve:

> cd ~
> serve

And then use Ctrl + c

Then go to http://localhost:5000 to confirm nothing is being served.

Ruling answered 4/1, 2018 at 5:26 Comment(0)
G
12

You can use the command below:

$ killall -9 node
Gora answered 4/2, 2021 at 21:54 Comment(1)
This would kill every node run you have...And may be you have other node run you want to keep. Better to search for the specific pid.Gilboa
R
6

I had the same problem when using serve for production build. I terminated the port instead of stopping Serve.

sudo fuser -k <portno>/tcp

Rossanarosse answered 7/11, 2019 at 10:16 Comment(0)
A
1

Just close "local console" on which you were ran your npm

Amadus answered 19/9, 2020 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.