- Published on
How to change the default React port when using create react app
- Authors
- Name
- Yair Mark
- @yairmark
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
startscript in thepackage.jsonupdatestartto:
...
"scripts": {
"start": "PORT=3006 react-scripts start"
...
}
...
- Add the PORT to a
.envfile 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.