1

I could able to start react js with default port 3000. But, when I customised the port to 4200, "start": "PORT=4200 react-scripts start"(Just changed in the package.json), I am not able to start the react js application.

'PORT' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-app@0.1.0 start: `PORT=4200 react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional lo
ging output above.

npm ERR! A complete log of this run can be found in:
Emile Bergeron
  • 16,148
  • 4
  • 74
  • 121
java learning
  • 31
  • 1
  • 1
  • 3

2 Answers2

16

to start APP on another port run the following npm command

npm start --port 3002

or to config in package use

replace the start command with below

"start": "set PORT=3006 && react-scripts start"
Manrah
  • 491
  • 3
  • 13
10

An other option that was not mentioned in the other answer would be to create a .env file in the root directory and put PORT=4200 in it. It will automatically be loaded in your environment variables.

Antoine Gagnon
  • 611
  • 4
  • 13