compose-mysql-helloworld-nodejs is a sample Bluemix application which shows you how to connect to an IBM Compose for MySQL for Bluemix service using Node.js.
-
If you do not already have a Bluemix account, sign up here
-
Download and install the Cloud Foundry CLI tool
-
Clone the app to your local environment from your terminal using the following command:
git clone https://github.com/IBM-Bluemix/compose-mysql-helloworld-nodejs.git
-
cd
into this newly created directory -
Open the
manifest.yml
file and change thehost
value to something unique.
The host you choose will determinate the subdomain of your application's URL: <host>.mybluemix.net
- Connect to Bluemix in the command line tool and follow the prompts to log in.
$ cf api https://api.ng.bluemix.net
$ cf login
- Create the Compose for MySQL service in Bluemix.
Note : The Compose for MySQL service does not offer a free plan. For details of pricing, see the Pricing Plans section of the Compose for MySQL service in Bluemix.
$ cf create-service compose-for-mysql Standard my-compose-for-mysql-service
- Push the app to Bluemix.
$ cf push
Now when you visit <host>.mybluemix.net/
you will be able to view and add words to the words table.
File | Description |
---|---|
server.js | Establishes a connection to the MySQL database using credentials from VCAP_ENV and handles create and read operations on the database. |
main.js | Handles user input for a PUT command and parses the results of a GET command to output the contents of the MySQL database. |
The app uses a PUT and a GET operation:
-
PUT
- takes user input from main.js
- uses the
connection.query
method to add the user input to the words table
-
GET
- uses
connection.query
method to retrieve the contents of the words table - returns the response of the database command to main.js
- uses
The sample web application includes code to track deployments to Bluemix and other Cloud Foundry platforms. The following information is sent to a Deployment Tracker service on each deployment:
- Application Name (application_name)
- Space ID (space_id)
- Application Version (application_version)
- Application URIs (application_uris)
This data is collected from the VCAP_APPLICATION environment variable in IBM Bluemix and other Cloud Foundry platforms. This data is used by IBM to track metrics around deployments of sample applications to IBM Bluemix. Only deployments of sample applications that include code to ping the Deployment Tracker service will be tracked.
Deployment tracking can be disabled by removing require("cf-deployment-tracker-client").track();
from the beginning of the server.js
file.