Deploying to Amazon EC2
Prerequisites
- Amazon EC2 Instance
- NodeJs
- Nginx
- PM2 (optional)
The guide to the above prerequisites can be found here
Step 1: Build and Transfer files to Amazon EC2 Instance
- Build the Application for the production environment
$ npm run build
- Zip the dist folder
$ tar cvfz dist.tar.gz dist
- Copy the Zip file to the Amazon EC2 Instance
$ scp -i /path/my-key-pair.pem /path/dist.tar.gz [email protected]:~/path
Step 2: Deploy the code
- Connect to your Amazon EC2 Instance using SSH.
- Unzip the tar file and move it to desired dirtectory using the following command:
$ tar xvzf dist.tar.gz && mv dist /path/
- Start the server using:
$ node server.js
- (Optional) Start the process using any of the process managers(pm2 here):
$ cd /path && pm2 start server.js --name="my-site" -i 3 --watch