Deploy create-react-app with PM2
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:
- create-react-app installed
- running express with entrypoint in server/index.js on localhost:3000 if no port is provided
Steps:
npm install -g pm2
- cd into your project directory then
pm2 ecosystem
- 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:
- npm command not found: https://github.com/Unitech/pm2-deploy/issues/41
- git issue publickey: https://github.com/Unitech/pm2-deploy/issues/130