A Cloud medley with IBM Bluemix, Cloudant DB and Node.js
Tinniam V Ganesh 270004Y158 Visits (7798)
Here is an interesting Cloud medley based on IBM's Bluemix PaaS platform, Cloudant DB and Node.js. This application creates a Webserver using Node.js and uses REST APIs to perform CRUD operations on a Cloudant DB. Cloudant DB is a NoSQL Database as a service (DBaaS) that can handle a wide variety of data types like JSON, full text and geo-spatial data. The documents are stored, indexed and distributed across a elastic datastore spanning racks, datacenters and perform replication of data across data
This application on Bluemix uses REST APIs to perform the operations of inserting, updating, deleting and listing documents on the Cloudant DB. The code can be forked from Devops at
1) Once the code is forked the application can be deployed on to Bluemix using
2) After this is successful go to the Bluemix dashboard and add the Cloudant DB service. The CRUD operations can be performed by invoking REST API calls using an appropriate REST client like SureUtils ot Postman in the browser of your choice.
Here are the details of the Bluemix-Cloudant application
3) Once the Cloudant DB service has been added to the Web started Node.js application we need to parse the process.env variable to obtain the URL of the Cloudant DB and the port and host to be used for the Web server.
The Node.js Webserver is started based on the port and host values obtained from process.env
2) Access to the Cloudant DB Access to Cloudant DB is obtained as follows
Access to the Cloudant DB is through the cloudant.url shown above
3) Once the access to the DB is setup we can perform CRUD operations. There are many options for the backend DB. In this application I have PouchDB.
4) Inserting a document: To insert documents into the Cloudant DB based on Pouch DB we need to do the following
The nice part about Cloudant DB is that you can access your database through the URL. The steps are shown below. Once your application is running. Click on your application. You should see the screen as below.
Click on Cloudant as shown by the arrow.
Next click on the "Launch' icon
This should bring up the Cloudant dashboard. The database will be empty.
If you use a REST API Client to send a POST API call then the Application will insert 3 documents.
The documents inserted can be seen by sending the GET REST API call.
The nice part of Cloudant DB is that you can use the URL to see your database. If you refresh your screen you should see the "books" database added. Clicking this database you should see the 3 documents that have been added
If you click "Edit doc" you should see the details of the document
5) Updating a document
The process to update a document in the database is shown below
This is performed with a PUT REST API call
The updated list is shown below
This can be further verified in the Cloudant DB dashboard for book3.
6) Deleting a document
The code to delete a document in PouchDB is shown below
The REST calls to delete a document and the result are shown below
Checking the Cloudant dashboard we see that only book2 & book3 are present and book1 has been deleted
7) Displaying documents in the database
The code for displaying the list of documents is shown below
As always you can use the "Files and Logs" in the Bluemix dashboard to get any output that are written to stdout.
Note: As always I can't tell how useful the command
Hope you enjoyed this Cloud Medley of Bluemix, Cloudant and Node.js!
Disclaimer: This article represents the author’s viewpoint only and doesn’t necessarily represent IBM’s positions, strategies or opinions
From my blog: Giga thoughts ...