To specify a port to run a create-react-app
based project, we can use the PORT
environment variable. Here’s how we can do it:
- Open our project’s
package.json
file. - Find the
"scripts"
section. - Modify the
"start"
script to include thePORT
environment variable. It should look something like this:
"scripts": {
"start": "PORT=3001 react-scripts start",
...
}
In this example, the port is set to 3001
, but we can replace it with any port number we prefer.
Alternatively, we can specify the port directly in the command line when we run the npm start
command:
PORT=3001 npm start
This will start our create-react-app
based project on port 3001
. Adjust the port number as needed for our project.