MKUltra
MKUltra

Reputation: 374

React start set port number from CLI

I'm attempting to start my react server through linux CLI with a specified port number. I am NOT asking about changing the package.json script to include a defined port number.

I need to be able to start multiple react instances with different ports through CLI.

I have seen recommendations such as

npm start --PORT=4000, npm start --PORT 4000, npm start -- --PORT=4000

Of which none work, they all set the port to the default of 3000, or if I have a defined port in the package.json such as 5000, it defaults to that.

Whats the correct command for setting the port through CLI?

Upvotes: 0

Views: 2345

Answers (2)

Syafrizal Akhzan
Syafrizal Akhzan

Reputation: 39

you can do it by adding PORT=4000 before react-scripts start in package.json.

"scripts": {
   "start": "PORT=4000 react-scripts start"
}

then you can execute npm start

Upvotes: 3

yekanchi
yekanchi

Reputation: 843

It's actually an environment variable for the port, so you can specify a PORT environment variable beforenpm start

export PORT=3005; npm start #For Linux
$env:PORT=3005; npm start #For Powershell

Upvotes: 2

Related Questions