5

My project is based on create-react-app. npm start or yarn start by default will run the application on port 3000 and there is no option of specifying a port in the package.json.

testAcc
  • 53
  • 1
  • 3

4 Answers4

14

Just update a bit in webpack.config.js:

devServer: {
    historyApiFallback: true,
    contentBase: './',
    port: 3000 // <--- Add this line and choose your own port number
  }

then run npm start again This will set the default port for that app to the on you specified

Alternatively: 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"
Sanchit Bhatnagar
  • 874
  • 2
  • 10
  • 16
1

With create react app, you can create a file called .env at the root level, and put the following code inside it :

PORT=3129

Abhinav Manchanda
  • 6,546
  • 3
  • 39
  • 46
1

Add .env file in source folder and add entry like below

PORT=9001
krishna chandak
  • 391
  • 5
  • 6
-1

run this code

yarn start --port 30022
OmidDarvishi
  • 558
  • 4
  • 8