How to deploy React and Node app on AWS: A better approach

  • Make a production build of your react app
  • Put these files manually in the public folder of your node server
  • Enable node.js to serve static files
  • Setup node.js, postgres on the aws EC2 instance
  • forward request to port 80 to node.js server
  • Building react app
  • Copy react files to node.js public folder
  • Deploy the node.js app

New architecture

Use of nginx to serve react code and act as a reverse proxy for the node server

New Workflow

CI and CD for react app
CI and CD for node app

Deploy Node App

Deploy React App

gitlab config for the react app
Deploy script for react app on AWS

Configure Nginx

server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
root /home/ubuntu/hssfrontend/dist;
index index.html index.htm index.nginx-debian.html;
}
server_name _;
location /api/ {
proxy_pass http://localhost:8000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

--

--

--

Senior Staff Engineer @freshworks. Ex-McKinsey/Microsoft/Slideshare/SAP, Tech Enthusiast, Passionate about India. Opinions are mine

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhinav Dhasmana

Abhinav Dhasmana

Senior Staff Engineer @freshworks. Ex-McKinsey/Microsoft/Slideshare/SAP, Tech Enthusiast, Passionate about India. Opinions are mine

More from Medium

What is true wisdom?

To My Dream Girl — 4

Self-Respect