How to Run React JS Project in Different Port?
Oct 10, 2022 . Admin
Hello Friends,
This article will provide an example of how to run react js project in a different port. let’s discuss run react js project in a different port. I would like to show you the run react js app in a different port. This article will give you a simple example of react js run a project in a different port. You just need to some steps to done react js to run a project in a different port.
In this example, we learn to run react js project in a different port. I will explain run diffrent port react js app. So, users need to change the default port of one of the react app.
So, let's start following example:
Example 1: Create an environment variableThis is the simplest method to change the default port of the react app.
Create the .env file inside the project directory and add the environment variable.
.envPORT=5000
Now you can run your app:
npm startExample 2: Specify port with the run command
PORT=5000 npm startExample 3: Edit the package.json file
In this method, we have to edit a single line of code inside the package.json file.
Edit the first line of the “scripts” object and they have to add the below code there.
package.json"start": "set PORT=5000 && react-scripts start"
Then after run your app:
npm start
I hope it can help you...