Installing Loopback on Amazon EC2 or Digital Ocean (Ubuntu)

Achint Verma
2 min readJan 24, 2016

--

Loopback is an awesome framework for building enterprise grade APIs. You can follow steps below to setup and get Loopback running on AWS server in minutes.

PREREQUISITES:

  1. Your AWS EC2 / Digital Ocean instance is setup.
  2. You have your ssh keys and can login on server using terminal or putty(for windows users).
  3. Your AWS instance port 80 is open so default web page can be opened. You can add an inbound rule for user group. This is not needed for Digital Ocean as they have port 80 open by default.

1: INSTALL NODE

The very first step is to install Node on your server. You can either follow instructions on official website or simply run following commands.

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

2: INSTALL COMPILER TOOLS

Loopback requires certain compiler tools to build the Loopback. Run following commands to install or update compiler tools.

sudo apt-get update
sudo apt-
get install python-software-properties python g++ make
sudo apt-get install build-essential

3: SETUP SWAP SPACE

Loopback requires at least 1GB RAM to during build process, and this is a common reason why Loopback builds fail on virtual machines like EC2 running on 1GB or low RAM. Workaround for this is to add SWAP space on system.

Check if your instance already has a SWAP setup by using free command. You should see swap memory information if SWAP is setup and enabled. Please follow these commands to setup 1GB swap space.

cd /var
sudo touch swap.img
sudo chmod 600 swap.img
sudo dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
sudo mkswap /var/swap.img
sudo swapon /var/swap.img

You can run free command to check if its working. To learn more on this topic, you can read this article from Digital Ocean fellas.

4: INSTALL LOOPBACK

Finally, we are ready to install Loopback. Please run following command to install. Please note that this may take about 5–10 minutes depending on computing capacity of your instance.

sudo npm install -g strongloop

5: CREATE YOUR FIRST LOOPBACK APP

Awesome, if you got previous command finished successfully. You can run slc command on terminal. Assuming that we want to create our app in /var/www folder, please run following commands.

sudo chown -R ubuntu:ubuntu /var/www
cd /var/www
slc loopback

If you see loopback application information, you are all set. If you have any trouble, please feel free to post in discussion below.

If you want to use MongoDB along with Loopback, you can follow next steps.

Extra Credits

1: INSTALLING MONGODB

Since Node applications works great with MongoDB, it is usually common backend. You can follow steps on official documentation page to install MongoDB.

https://docs.mongodb.org/master/tutorial/install-mongodb-on-ubuntu/?_ga=1.151994681.162877620.1442443844

After installation finished, run following commands to create a database and a user.

mongo> use your-database-name> db.getSiblingDB(“your-database-name”).runCommand({createUser: “db-username”, pwd: “db-password”, roles: [“dbOwner”]})

Please note that we need to add MongoDB connector to Loopback application before we can use it. You can follow this article from Loopback official documentation to do so.

--

--

Achint Verma

Just another tech guy with curiousity for latest in tech and it's applications