0

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?

1
  • 1
    try PORT=4000 npm start Commented Apr 22, 2019 at 4:11

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.