Deploy create-react-app with PM2

Ygam Retuta
Ygam Retuta
Published in
1 min readJul 26, 2017

--

we want to deploy a create-react-app on a virtual server because for some reason we cannot use a cloud-based deployment

Assumptions:

  1. create-react-app installed
  2. running express with entrypoint in server/index.js on localhost:3000 if no port is provided

Steps:

  1. npm install -g pm2
  2. cd into your project directory then pm2 ecosystem
  3. edit ecosystem.config.js with:

4. edit package.json scripts part withwith

5. setup: pm2 deploy ecosystem.config.js staging setup

6. deploy: pm2 deploy ecosystem.config.js staging

7. setup whatever proxy server you want to use. here is an example for nginx:

listen 80 default_server;server_name _;location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header Connection ‘upgrade’;
proxy_cache_bypass $http_upgrade;
}

Gotchas:

  1. npm command not found: https://github.com/Unitech/pm2-deploy/issues/41
  2. git issue publickey: https://github.com/Unitech/pm2-deploy/issues/130

--

--