Reputation: 374
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
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
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