Deploying Node, Mongo to AWS EC2

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 nodejs

Installing Node installs NPM.

Install Express on your VM

sudo npm install -g express

Change 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 8080

See 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 install

Start your server

node server.js

Visit 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/

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.