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
JMS786
  • 1,103
  • 2
  • 11
  • 22

5 Answers5

43

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

Marc Scheib
  • 1,963
  • 1
  • 24
  • 29
  • 4
    but when I visit localhost:5000, the App is still running. Shouldn't it stop running as well when I press `Ctrl + c` ? – JMS786 Jul 27 '17 at 10:02
  • 1
    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 `. I tested it locally and everyhting works fine for me. Perhaps your browser is somehow serving the page from cache. – Marc Scheib Jul 27 '17 at 10:38
  • @JMS786 does the app still load when you refresh using `Ctrl + F5`? – RyanZim Jul 27 '17 at 14:30
  • 1
    @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. – JMS786 Jul 27 '17 at 16:28
  • 1
    in my case is not cache. another option? – corlaez Dec 11 '17 at 17:13
  • 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. – mikael1000 May 24 '18 at 00:42
  • it does not work. I am using VS Code terminal. Thanks – MindRoasterMir Apr 11 '20 at 12:23
13

You can use the command below:

$ killall -9 node
juliomalves
  • 42,130
  • 20
  • 150
  • 146
brugobi
  • 259
  • 3
  • 5
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.

Alonso Robles
  • 401
  • 3
  • 5
5

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

sudo fuser -k <portno>/tcp

Choxmi
  • 1,584
  • 4
  • 29
  • 47
1

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

David Melkumyan
  • 199
  • 1
  • 4