setting PORT and HOST manually for facebook/create-react-app production build

Viraj picture Viraj · Aug 17, 2018 · Viewed 8.2k times · Source

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/

Answer

Idan Dagan picture Idan Dagan · Aug 17, 2018

From react docs:

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

serve -p 7000 -s build