Brewing a potion with Bluemix, PostgreSQL, Node.js in the cloud
Tinniam V Ganesh 270004Y158 Visits (7735)
Here is a heady potion made with the key ingredients of IBM's Bluemix, PostgreSQL & Node.js. In this post I instantiate an app 'mypgdb01' on IBM's Bluemix which uses the services of PostgreSQL in the cloud. This is shown in the picture below.
The mypgdb01 is a Webserver running on Node.js in Bluemix and uses the services of PostgreSQL DB. The app mypgdb01 performs basic CRUD (Create, Remove, Update & Delete) on the PostgreSQL.
1) This app uses the Node.js Webstarter kit and the PostgreSQL service. The Node.js Webserver is created by parsing the VCAP services variable as usual
The details of VCAP_SERVICES can be see by clicking Runtime for you application and is shown below
Note: From above it can be seen that the PostgreSQL DB's host & port is
This different from the host & port of the Node.js Webserver which can be see in Logs & Files tab (included below) and is
2) Once the Webserver is started the server waits for REST calls of GET,PUT, UPDATE & DELETE as shown below.
3) The REST API call are implements as follows
4) Once the changes are made you can push the changes to Bluemix using 'cf' commands.
The commands are
5) In the Bluemix dashboard the app 'mypgdb01' should be up and running.
6) To invoke the different database operations we need to make REST API calls to the app.
7) To make the REST API calls you can install Sure Utils -> REST API Chrome extension. I installed the SureUtils-.REST API Client. This is a Chrome extension and can be installed from Chrome Web Store (search for REST API client). You could choose any REST API client of your choice for the browser you intend to use (Chrome, Firefox)
8) Now we can test the Nodejs-PostgreSQL app with the Sure Utils - Chrome extension
8) The following REST API calls can be made to test the PostgreSQL operations on the database
GET - select
UPDATE + GET - update + select
The PUT API updates Anand Karthik to Kumar Karthik. This is shown in the GET API call
.DELETE + GET - delete + select
Here the DELETE API call deletes the Kumar Karthik record. The GET API call now displays only 1 record.
The console.log output in Bluemix can be see in Files and logs -> stdout.log as shown below
The above post shows some basic operations done on a cloud based application that is composed of a Webserver with a PostgreSQL as a backend. The code can be enhanced by adding front end using Node express.
From my blog: Giga thoughts...
Disclaimer: This article represents the author’s viewpoint only and doesn’t necessarily represent IBM’s positions, strategies or opinions