Setting up a Create-React-App with PM2 and Nginx on AWS EC2

Recently, I was working on a project and wanted to host it online. In addition, I didn’t wanted to use Heroku as I thought that it abstracts too much of the server configurations and I myself wanted to test the server configs that I intended to use for production.

One of the hurdles that I came across was starting the development server on EC2 in the background and many solutions suggested the use of react-scripts build functionality. But, that was not what I intended using. So below is my setup and configuration for starting the development server

Let’s start setting up our server with Node and NPM using the PPA mode.

First, install the NodeJS PPA in order to get access to its contents. Make sure to replace the 12.x with the latest stable version.

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

verify your installation with below commands

nodejs -v
npm -v

Next we install the global npm dependencies

sudo npm i -g pm2@latest