Create an environment variable
This is the simplest method to change the default port of the react app. We need to create the .env file inside the project directory and add the environment variable. Users need to add the below code inside the .env file.
PORT=<specify_port_of_your_choice>
Example:
PORT=5000
Now, run the project using the npm start command, and react app will automatically start to run on the port of your choice.
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.