0

When creating a react app, I run these commands in my terminal:

  1. npx create-react-app app-name
  2. npm install
  3. npm start

npm start allows me to view my project locally, but I accidently closed my terminal before running ctrl + c to end it. The browswer tab containing localhost 3000 (the npm start default host) has been closed for a while now, but my project can still be viewed there everytime I follow that link. Now everytime I run npm start it tells me that localhost 3000 is taken and I have to input another command and run it on localhost 3001. I've made this mistake a few times. I don't mind doing this, but it got me wondering if there is a global version of ctrl + c that will close all of these at once.

  • have you tried `ps aux` followed by `kill 12345` where 12345 is an example of a PID (process ID) that you read from an output line of the ps command and that looks like what you want to stop? – Walter Tross Dec 04 '20 at 22:35
  • Firstly, make it clear which OS you are on. Secondly, you should search within your running/started processes and kill the already started process. Beside @WalterTross suggestion, you can use netstat and see which process is using port 3000. – Davood Falahati Dec 04 '20 at 23:45
  • I forgot: `kill -9 12345` is more guaranteed to work (it sends the `SIGKILL` signal instead of the default `SIGTERM` one) – Walter Tross Dec 04 '20 at 23:50

1 Answers1

1

Firstly, I think you've had a misconceptions here: closing the browser tab will never end the server that you've started (i.e. the server npm start created).

For your question I think you can use the approach of killing a process based on the port they're occupying in this question: Find (and kill) process locking port 3000 on Mac

Envil
  • 2,687
  • 1
  • 30
  • 42