Published on

How to change the default React port when using create react app

Authors

When you use create-react-app to generate the scaffolding for your React app the default port is 3000. But if you want to change this to something else it is not too obvious how you would go about doing this.

After a bit of a search through the code and then on Google I found you achieve this in 2 ways:

  • In the start script in the package.json update start to:
...
"scripts": {
  "start": "PORT=3006 react-scripts start"
...
}
...
  • Add the PORT to a .env file in the root of your project:
PORT=3006

The option you choose is up to your personal preference. Personally I like the second option as you expect configurations to be there and not hardcoded in the package.json file.