Deploying Node, Mongo to AWS EC2
Aug 29, 2017 · 1 min read
This guide assumes you have already set up the environment and downloaded the .pem file. Make sure you put the .pem key somewhere safe.
Connect to environment
Click on your instance and hitting “Connect” — you’ll see a URL like this. Copy and paste it into terminal:
ssh -i “<LOCATION OF PEM KEY>” ubuntu@<amazon aws url>
Install Mongo on your VM
The documentation is on point: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
Install Node on your VM
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejsInstalling Node installs NPM.
Install Express on your VM
sudo npm install -g expressChange IP tables on your VM
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -o lo -j REDIRECT --to-ports 8080See this guide for reference.
Edit your security groups on AWS

Clone your git repo
In /home/ubuntu:
git clone https://github.com/<YOURUSERNAME>/<YOURREPO>.git
npm installStart your server
node server.jsVisit your new page
Get your public DNS from your Amazon console page.
<amazon public DNS here>:8080
e.g. http://ec2-44-146-1-324.us-east-1.compute.amazonaws.com:8080/
