Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default localhost port for React App [duplicate]

I downloaded the React App package from the link create-react-app. The default port it assigns is port:3000

How to Change this port to a custom port like 3002 or 3006 ?

like image 799
Sanchit Bhatnagar Avatar asked Jun 15 '18 05:06

Sanchit Bhatnagar


People also ask

How do I change the localhost port in react app?

To change the default port for a create-react-app project, update the start command in your package. json file to specify the port, e.g. "PORT=3456 react-scripts start" on macOS and Linux and "set PORT=3456 && react-scripts start" on Windows.

What is the default localhost server port in react JS?

When we create a new react app using the npx create-react-app command, the default port for the app is 3000. We can access the app from the localhost:3000.

How do I change my localhost port?

Open C:\xampp\apache\conf, find the httpd. conf file and open with notepad++. Look for these lines and change 80 in the last line any other port, for example 8080. This way we will be able to run Apache but the http://localhost/url won't work for that you need to append port number into the URL.


1 Answers

modify part of package.json from:

"start": "react-scripts start"

for Linux and MacOS to:

"start": "PORT=3006 react-scripts start"

Windows to:

"start": "set PORT=3006 && react-scripts start"
like image 102
nishant Avatar answered Oct 06 '22 06:10

nishant