6

i used facebook/create-react-app to create a react application and successfully got production build running on http://localhost:5000.

my question is is there any way to change the 5000 PORT in this production build ?

according to the Advanced Configurations, there is no way to change HOST and PORT in production, only available for the development

https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#advanced-configuration.

this is my package.json

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "deploy": "serve -s build"
  }

this is my .env

##
HOST=127.0.0.1
PORT=8008
## PUBLIC_URL=http://myexamplesite.lk/
##

REACT_APP_ROOT_BASE_URL=https://myexamplesite.lk/api/
REACT_APP_ROOT_BASE_URL_META=http://myexamplesite.lk/
Viraj
  • 638
  • 1
  • 8
  • 10

2 Answers2

2

From react docs:

"the port can be adjusted using the -p or --port flags."

serve -p 7000 -s build
Idan Dagan
  • 10,273
  • 5
  • 34
  • 41
  • thanks for the answer, i done this like "deploy": "serve -p 8080 -s build", but i have to add this every time i changing the port or i have to declare like, "deploy:dev": "serve -p 8080 -s build", "deploy:qa": "serve -p 9090 -s build" for every environment, my concern is to set this using a .env file – Viraj Aug 17 '18 at 06:59
2

create-react-app listed all .env files which can used when run npm run build To change PORT in local production build you can create a file name .env.production.local and set the PORT you want:

##
HOST=127.0.0.1
PORT=5000
## PUBLIC_URL=http://myexamplesite.lk/
##

REACT_APP_ROOT_BASE_URL=https://myexamplesite.lk/api/
REACT_APP_ROOT_BASE_URL_META=http://myexamplesite.lk/
Tony Nguyen
  • 3,298
  • 11
  • 19