Reputation: 1692
I am new to React. I was working on a sample React program. But I noticed a strange behavior. 2 days back I ran a sample React program, now again I ran a different sample React program. But what I noticed was instead of showing the latest application, my localhost was still showing the old React application. Also when I ran the 2nd application today, I got a message indicating "Something is already running on port 3000.". What could be the reason? Why is it showing the old one instead of new application?
Upvotes: 1
Views: 1166
Reputation: 582
When you run a react app with npm start
, it sets up a server that takes up a port (or URL) on your computer.
When you try to run another react app, it will try to go on the default port (3000), but if something else is running, it can't take up the port. If you're running one app on port 3000 and want to run another, you have to specify another port.
If you use create-react-app
, it will prompt you if port 3000 is already taken, and offer you the option to run on another port (3001)
Upvotes: 1
Reputation: 870
This happens because you never killed your old application, so it was still running on port 3000. The message you got told you that your second application couldn't grab access to port 3000. So after that, when you opened your browser up to port 3000, it was still the old application because that's what was holding that port open.
Once you manually killed the old application, it freed up port 3000, which could then be used for the second application.
Upvotes: 2
Reputation: 1692
Anyways, I manually killed the process running on port 3000 through command prompt after which the latest application is reflecting.
Upvotes: 0