Edit the package.json file
In this method, we have to edit a single line of code inside the package.json file. Here, The user will find the code like “start”: “react-scripts start” inside the “scripts” object. In the below image, you can see the default view of the “scripts” object.
Users need to edit the first line of the “scripts” object and they have to add the below code there.
"start": "set PORT=<specify_port_of_your_choice> && react-scripts start"
Example:
"start": "set PORT=5000 && react-scripts start"
After editing the package.json file, your “scripts” object should look like the below image.
How to specify a port to run a create-react-app based project ?
Usually the react app server runs on the port 3000. But there may be some situations, where user needs to specify a port to run the react app. So, users need to change the default port of the application and sepcify a custom port to run the application.
Contact Us