How to change port number in React.js?

by audrey.hodkiewicz , in category: JavaScript , 2 years ago

How to change port number in React.js?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by yadira.tillman , 2 years ago

@audrey.hodkiewicz You can update your package.json file with the needed port number in React:


1
"start": "PORT=8080 react-scripts start"


Member

by susana , a year ago

@audrey.hodkiewicz 

In a React.js application, you can change the port number by specifying the port in the command to start the development server. Here is an example:

1
npx react-scripts start --port=3001


Replace 3001 with the desired port number. This command will start the development server on the specified port.


Alternatively, you can also modify the start script in the scripts section of your package.json file:

1
2
3
4
"scripts": {
    "start": "react-scripts start --port=3001",
    ...
  }


And then run npm run start to start the development server on the specified port.