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.
Basically just open a shell window and type the following line :
$ npm install -g strongloop for more information just go their website loopback website
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 TestServerthen 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.
First you need to create a Mongolab account, to do so you need to go to the Signup Page and signup .
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
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.
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 !
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.
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 initFollowing to this, you will have to login into your heroku account through the bash window opened before :
$ heroku loginThen 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 TheNameOfYourAppAfter that follow the instruction given on the shell command to upload your server online
$ git add .
$ git commit -m "First commit"
$ git push heroku masterOnce 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 /explorerPS : you can also go directly to http://TheNameOfYourApp.herokuapp.com/explorer



