How to deploy Loopback ? Need simple explanation
Asked Answered
A

3

6

I have developed a Loopback API and would like to deploy it to a test instance (Heroku or Digital Ocean, probably).

It is quite complicated to understand how to deploy it. There seems to be many solutions out there, from StrongLoop Process Manager to a plain Node.js server... The information is not very digest so could anyone help me out understand what possibilities I have to deploy it and what are the pro/cons of each one.

I am reading some documentation right now but feel a bit lost. Some input from people who have already deployed it would be great, I can't be the only one to feel confused at this point.

Adduction answered 18/4, 2016 at 14:15 Comment(0)
S
5

First difference is if you are planning to host it on a server (Digital Ocean) or as a hosted node process (Heroku).

On Heroku you need to understand their way of doing it, but once done can save you a lot of worry on infrastructure management. This would not include StrongPM and Heroku is already it's own processmanager. If you have basic understanding of Git and don't use advanced stuff eg. with OS dependencies, this is the easiest in the long run. Don't have experience, but it would seem that Heroku works directly of a Git repository, so working with Git is a requirement for this model.

On a server (eg. digital ocean), you need to decide on an OS and set that up with dependencies, install node, DBs, ect. Once does you can manage your node process with a process manager, eg. StrongPM, though I've had mi battle with it and long ago decided to go with PM2 as process manager, which I found much easier to understand and handle, both initially and in the long run. But the basic is the same as on your local machine, you just need it to run "node server.js", a process manager just gives it some more bells and whistles (auto restart on error, monitoring and repeatable process start, being the main things).

Spiraea answered 21/4, 2016 at 8:44 Comment(2)
OK great, I didn't get that huge difference. I tried Heroku and you are right, it does save some worry but create others... I am trying to have an all-in-code infrastructure and Docker seems to be the best approach for me to handle the DB + Loopback, be flexible and still have all my code versioned. Thanks for the reply anyway, mich appreciatedAdduction
What about handling deployments on Digital Ocean through StrongLoop Process Manager(SLC), which LoopBack's documentation seems to suggest? docs.strongloop.com/display/SLC/Deploying+applications+with+slcDelfeena
P
3

I have done this many times, and it can be fairly straightforward. The most complicated bit is setting up the database. For Heroku, you can't use filesystem storage (e.g. storing everything in a db.json file) because the filesystem is not persistent. So you need an external database, and luckily Heroku offers a few of these as addons, e.g. mLab for MongoDB which I highly recommend.

Once you've provisioned the database, make sure the correct details are configured for the datasource. Here is an example from a Heroku-hosted app using mLab (I've xxxx-ed out a few details):

"db": {
  "host": "ds043471-a0.mongolab.com",
  "port": 43471,
  "database": "heroku_appxxxxxxx",
  "username": "heroku_appxxxxxxx",
  "password": "xxxxxxxxxx",
  "name": "KaranMongo_live",
  "connector": "mongodb"
}

You can even test this locally now (though best practice is to use separate datasource json files for development/production).

Next, you need to make a few adjustments to make your application "Heroku-ready":

  1. Add the Strongloop buildpack, i.e. heroku buildpacks:set https://github.com/strongloop/strongloop-buildpacks.git
  2. Create a Procfile, which only needs one line: web: slc run

Then push to your heroku app (assuming you've set up the remote correctly):

git push heroku master

Magic. It builds and deploys.

Patten answered 26/7, 2016 at 14:8 Comment(2)
Is it possible to use loopback on my own server? All options offered are payments and trial. I mean that loopback is not free, is it a commercial framework?Tyronetyrosinase
Yes you can definitely use Loopback on your own server. You just run it like any other Node process. PM2 Is good for this.Patten
P
2
  1. Follow guide here to install NodeJS How To Set Up a Node.js Application for Production on Ubuntu 16.04 but instead of pm2 start hello.js enter your pm2 start server/server.js

  2. Edit your ngnix config file sudo nano /etc/nginx/sites-available/default

    location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }

  3. Restart nginx sudo systemctl restart nginx

Plumate answered 3/10, 2017 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.