Server side application running on Loopback with data persisted on MongoDB.
- Install MongoDB on your machine, run the MongoDB instance and create an empty DB called days-off
- clone this days-off-loopback repository on your local machine
- move to the folder you have just downloaded
- run
npm install
to install the required node modules - run
node .
to launch the application - check out and test the API methods on http://localhost:3000/explorer
Moving days-off-loopback to IBM Bluemix is pretty easy, all you need is to do is following this procedure:
On IBM Bluemix
- get a Bluemix account
- add a Loopback Starter application (e.g.
days-off
) - add a Cloudant NoSQL DB service and create a database
- get the "Cloud Foundry" tools from the "Getting started" page
On your local machine
- add a manifest.yml file to your copy of days-off-loopback
- replace any reference to your local MongoDB instance with the credentials of a Cloud DB (e.g. Cloudant)
- push your application to IBM Bluemix using Cloud Foundry. E.g.
cf push days-off
I have activated a trial using a promotional code and it will expire in June 2017. Some of the links provided below may be no longer valid after that date.
Manifest.yml is used by IBM Bluemix to understand how the application is configured. More details on https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html. This is an example of manifest.yml
applications:
- path: .
memory: 1024M
instances: 1
domain: mybluemix.net
name: days-off-cloudant
host: days-off-cloudant
disk_quota: 1024M
The cloud version of this application persists data on Cloudant, which is a "Database As A Service" provided by IBM Bluemix. Moving a Loopback application from MongoDB to Cloudant is pretty straightforward.
-
Create a Cloudant DBAAS application, enter its specific dashboard and create a database (e.g. "days-off")
-
In the Cloudant dashboard go to Account > CORS and make sure that CORS is enabled and that "Databases will accept requests all the domains"
-
Get the credentials from "Cloud Foundry Apps > Connections > View Connections". You will get something like this
{
"cloudantNoSQLDB": {
"name": "Cloudant-3s",
"label": "cloudantNoSQLDB",
"plan": "shared",
"credentials": {
"username": "someusername",
"password": "secret",
"host": "myhost-bluemix.cloudant.com",
"port": 443,
"url": "https://someusername:[email protected]"
}
}
}
- Now it's time to change the settings in days-off-loopback application. Go to server/datasources.json and replace it with something like this (of course you have to set your credentials
{
"db": {
"name": "db",
"connector": "memory"
},
"Cloudant": {
"url": "https://someusername:[email protected]",
"database": "days-off",
"username": "someusername",
"password": "secret",
"name": "Cloudant",
"modelIndex": "",
"connector": "cloudant"
}
}
- Finally, go to
model-config.json
and replace all the references to MongoDB with "Cloudant"
You can take advantage of the Swagger API explorer that is built-in with Loopback. It is available here https://days-off-cloudant.mybluemix.net/explorer/. As an alternative, you can run this Postman collection
The order of the methods in the Postman collection represents a test suite that covers all the methods used by the available clients.