Install and add cross-env package
First, we need to install the “cross-env” package in the project directory. So, open the terminal and run the below command inside the project directory.
npm i -D cross-env
devDependencies in package.json
{
"devDependencies": {
"cross-env": "^7.0.3"
}
}
After installing the cross-env package, the user needs to edit the first line of the “scripts” object inside the package.json file. Users need to change the below code by removing the first line inside the “Scripts” object.
"start": "cross-env PORT=<specify_port_of_your_choice> react-scripts start"
Example:
"start": "cross-env PORT=5000 react-scripts start"
Your “Scripts” object should look like the below image after making changes inside the code.
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