DEV Community

equuscaballus
equuscaballus

Posted on

Something is already running on port 3000

Hi Everyone
I have downloaded a few react project from github for study purpose. When I run the project with the command npm start I got this error message : "Something is already running on port 3000".

Now I if I restart the PC then I can run the project again. How can I run the projects without restarting the PC ? What's the solution ?

Top comments (22)

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

You can simply execute npx kill-port 3000 to kill the process which is using port 3000

Collapse
 
doepicshit0305 profile image
DoEpicShit0305

this isn't working I also tried, but still seeing ? Something is already running on port 3000. in my terminal, I restarted as well still same issue

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

Even after restarting the machine you're getting the error means something is added as a service which automatically starts on restarting the machine. You need to identify that and remove it.

Thread Thread
 
doepicshit0305 profile image
DoEpicShit0305

How do I check which service is running , because I have tested and nothing seems coming on this port

Collapse
 
dbugshe2 profile image
maroof shittu

simply best solution, in my opinion

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

Glad you found it useful 🙂

Collapse
 
aledileo profile image
Alejandro Di Leo

Hi! Are you trying to run those few projects at the same time? If that's the case, it's possible that by default they will try to use that same port. Normally you can set PORT as an env variable to tell the project to run that specified port (this depends on the server being used). You can try running PORT=3001 npm start (or an equivalent to set env variables per command in your OS), changing the port value for each project

Collapse
 
equuscaballus profile image
equuscaballus

Hi

Thanks for the reply. Actually now while running the project if I change the port number then it runs !

Thank you for your help :)

Collapse
 
doepicshit0305 profile image
DoEpicShit0305

actually, you still didn't solve you problem, think how could you have been solved with changing the port, you should figure out, I am also facing same issue, but I also don't want to restart it and nor want to change the port

Collapse
 
equuscaballus profile image
equuscaballus

I was wondering if there is any way to define the port number in the source code ? For example if I want to set a different port number for different project ?

Collapse
 
aledileo profile image
Alejandro Di Leo

It really depends on the server and implementation being used. For example if the project is using create-react-app, you can create a .env file with all your project based env variables. This is because create-react-app uses dotenv. If you can find this out or you're able to share the github repo I may be able to assist further

Thread Thread
 
equuscaballus profile image
equuscaballus

I just downloaded the projects form github randomly. couldn't find the repository URL. Do you know in which file of the source code the port number is defined ?

Thread Thread
 
aledileo profile image
Alejandro Di Leo • Edited

That also depends on the server being used. You can check the package.json file for more info, for example the scripts part. What is the value for the start command?

Thread Thread
 
equuscaballus profile image
equuscaballus

I will check that . you are very helpful . Thanks a lot :)

Collapse
 
ekeijl profile image
Edwin

Sometimes the Node process just hangs and you need to stop it manually.
Enter this into your terminal if you want to check if something is still running at that port:

lsof -i :3000

Then you can stop the process in your terminal if you want.

Collapse
 
equuscaballus profile image
equuscaballus

tried that command but didn't worked

Collapse
 
alekseiberezkin profile image
Aleksei Berezkin

Hi! I used to encounter this error. It may happen if you close the editor or console with running node — sometimes editor doesn't close it. You may use your console or process explorer to find it and forcibly stop freeing the port.

Collapse
 
doepicshit0305 profile image
DoEpicShit0305

Can you help for this, how can I check in console what is running on port 3000 and how can I forcibly stop it any command for MAC, I am new MAC user

Collapse
 
doepicshit0305 profile image
DoEpicShit0305

I already checked running this command lsof -i :3000 seems noting is running on 3000, but still get the same error

Thread Thread
 
alekseiberezkin profile image
Aleksei Berezkin

Try running the same in sudo mode

Collapse
 
bijink profile image
Bijin K • Edited

In Linux you can see localhost ports working in background by typing jobs command.

Then you can kill the port by kill -kill <job number>
eg: kill -kill %1

Collapse
 
truong1308 profile image
Vũ Phi Trường

Cảm ơn bạn rất nhiều
I'm in VietNamese