Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set React Custom Port like 3129

Tags:

reactjs

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.

like image 827
testAcc Avatar asked Dec 11 '22 06:12

testAcc


1 Answers

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"
like image 147
Sanchit Bhatnagar Avatar answered Dec 28 '22 06:12

Sanchit Bhatnagar