Skip to content

this tutorial aims to show how to set up a looback server then to upload it to a heroku account while being linked to a mongolab Database.

Notifications You must be signed in to change notification settings

sofiane87/Tutorial-Loopback-Heroku-mlab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This tutorial aims to provide a quick example of how to set up a loopback server that is linked to a mongolab Database and then to set it online through a heroku account.

Step 1 : installing Loopback

Basically just open a shell window and type the following line :

	$ npm install -g strongloop  

for more information just go their website loopback website

Step 2 : creating the local server file

To do so, you will have to go to a folder in which you will save all your server files and then run a specific command :

	$ slc loopback # For the sake of this example, I would advise you to call your application TestServer

then simply follow the instruction on the screen which means choosing a name for the server and the associated files. I would advise you to choose the same name to avoid confusions.

Step 3 : configuring the MongoLab connection

First you need to create a Mongolab account, to do so you need to go to the Signup Page and signup .

singup page

Once you've signed up, you will need to create a new Data base. To do so, just loging and click on the "create new" button. Select the appropriate type of Database you would like (there is a free option if you just wand to try it)

create-new

Create a new database

Then, you will have to click on the database created ( which is now available on the main screen), and go to the Users tab and create a new user. this will give the proper credentials in order to properly communicate with the Database.

create a new user

once the user is signed up, just copy past the URI link provided above you will need it in the few next steps .

once this is done. we will go back to the folder TestServer where the server files are saved, you will have to open the file TestServer/server/datasources.json

add the following lines to the main braket :

  "mongodb": {
    "url": <your URI link>,
    "name": "mongodb",
    "defaultForType": "mongodb",
    "connector": "loopback-connector-mongodb"
  },

The URI link should start with something like : "mongodb://:@ds..." do not forget to replace the and by your password and user information without the "<" and ">" symbols.

once this is done, you will have to open the file TestSertver/server/modelconfig.json and change all the lines corresponding to "datasource" to the following line :

	"dataSource": "mongodb"

Finally, you will have to go to the TestServer/package.json file and add the following line to the dependencies section :

    "loopback-connector-mongodb": "^1.13.2",

Once this is done, your database is now totally linked to your loopback server. Congrats !

Step 4 : Upload on heroku

The tutorial assumes that you have a free Heroku account, and that you have Node.js and npm installed locally. if not please click here to get them.

First of all you will have to create an account on heroku, to do so just go on the heroku website and signup.

singup page

Once this is done, you will have to download and install the heroku toolkit

then start by defining the TestServer folder as a git folder, to do so, open a terminal and type the following lines :

	$ cd TestServer
	$ git init

Following to this, you will have to login into your heroku account through the bash window opened before :

	$ heroku login

Then enter your e-mail and password that you use to create your heroku account. you are now logged on your heroku account. We will then create a heroku app , to do so just type the following line on the command shell you previously opened

  $ heroku create TheNameOfYourApp

After that follow the instruction given on the shell command to upload your server online

  $ git add .
  $ git commit -m "First commit"
  $ git push heroku master

Once this is done, your server is online, you can open the webpage giving you access to the Rest API by type the following command :

  $ heroku open /explorer

PS : you can also go directly to http://TheNameOfYourApp.herokuapp.com/explorer

About

this tutorial aims to show how to set up a looback server then to upload it to a heroku account while being linked to a mongolab Database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published