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.
Asked
Active
Viewed 8,994 times
5
-
What OS? You have to set the PORT environment variable. – Andrew Li Jul 13 '18 at 05:23
-
https://github.com/facebook/create-react-app/issues/242 – Andrew Li Jul 13 '18 at 05:23
-
Possible duplicate of [How to specify a port to run a create-react-app based project?](https://stackoverflow.com/questions/40714583/how-to-specify-a-port-to-run-a-create-react-app-based-project) – Sanchit Bhatnagar Jul 13 '18 at 08:06
4 Answers
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