How to change default port number in react

Changing Default Port 3000 in create-react-app

In react application there is a default port number which is 3000. Whenever we try to run our initial created react application using create-react-app then it starts running on http://localhost:3000/. So now we have to do some changes in “scripts” tag into package.json file in case to run our application on a different port. By default we get the code is in package.json file as shown in the above image.

Now lets say we need to run our react application on port number 5000.

Now just make some changes in start tag under scripts tag and use below code.

For windows :

“start”: “set Port=5000 && react-scripts start”

Changing Default Port 3000 in create-react-app
Changing Default Port 3000 in create-react-app

For Ubuntu / MacOS :

“start”: “Port=5000 react-scripts start”

OR

“start”: “export PORT=5000 react-scripts start”

Changing Default Port 3000 in create-react-app
Changing Default Port 3000 in create-react-app

☕ Buy me a Coffee ➤ https://bit.ly/32f22mQ

Support me on Social Media :

youtube 🎥 :https://bit.ly/2IaMZUr
Instagram 📷 : https://instagram.com/openprogrammer
Twitter 🐦 : https://twitter.com/openprogrammer
Facebook 👍 : https://facebook.com/openprogrammer

Leave a Comment