solving "Port 3000 is in use" problem by killing a process in Git Bash

created at 01-13-2022 views: 4

In react app (mine is next app, the same thing), sometimes we will got the error:

warn  - Port 3000 is in use, trying 3001 instead.
ready - started server on, url: http://localhost:3001

although it opens a new port for us automatically, you may find you can't open that link in browser.

find the process

to find which process used the 3000 port, we use this command in Git Bash:

$ netstat -ano

it will lists all the processes.Our target is, the default port of React app , we can find a result like:

 Proto  Local Address          Foreign Address        State           PID
  TCP               LISTENING       2400

so the process PID is 2400 in my case.

kill the process in gitbash

if you use

kill -9 PID

You will get:

$ kill -9 2400
bash: kill: (2400) - No such process

the correct method is using this command:

taskkill //F //PID xxxx:

$ taskkill //F //PID 2400
SUCCESS: The process with PID 2400 has been terminated.

although this answer on stackoverflow got a down vote (don't know why), it works for me very well:

$ npm run dev

> dev
> next dev

ready - started server on, url: http://localhost:3000

now we are able to start the project again.

created at:01-13-2022
edited at: 01-13-2022: