Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React.js : How to start a react application on a different port

I just have started learning React.js and made two projects using Create React App.

Now if I want to start both projects at the same time, I can't because both start on port 3000 by default.

Is there any way I can change the default port of one of them to something else like http://localhost:3001 and run them simultaneously?

Note: I'm a Windows user

like image 623
Ankit Agrawal Avatar asked Jul 22 '26 00:07

Ankit Agrawal


2 Answers

Modify start command from scripts section of package.json.

"start": “set PORT=3005 && react-scripts start"

There are couple of other ways also. Refer this link https://tech.amikelive.com/node-830/reactjs-changing-default-port-3000-in-create-react-app/

PS: You can specify the port number which you want.

like image 81
Shreekesh Murkar Avatar answered Jul 25 '26 14:07

Shreekesh Murkar


You can create a .env file in the root of your project, and then put this in it:

PORT=3001

Then you don't have to worry about Windows vs Mac/Linux differences.

like image 20
ChillyPenguin Avatar answered Jul 25 '26 16:07

ChillyPenguin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!