pborel / compose-mysql-helloworld-nodejs

Shows you how to connect to an IBM Compose for MySQL for Bluemix service using Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

compose-mysql-helloworld-nodejs overview

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.

Running the app on Bluemix

  1. If you do not already have a Bluemix account, sign up here

  2. Download and install the Cloud Foundry CLI tool

  3. 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
  1. cd into this newly created directory

  2. Open the manifest.yml file and change the host value to something unique.

The host you choose will determinate the subdomain of your application's URL: <host>.mybluemix.net

  1. Connect to Bluemix in the command line tool and follow the prompts to log in.
$ cf api https://api.ng.bluemix.net
$ cf login
  1. 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
  1. 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.

Code Structure

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

Privacy Notice

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.

Disabling Deployment Tracking

Deployment tracking can be disabled by removing require("cf-deployment-tracker-client").track(); from the beginning of the server.js file.

About

Shows you how to connect to an IBM Compose for MySQL for Bluemix service using Node.js

License:Other


Languages

Language:JavaScript 60.4%Language:HTML 22.0%Language:CSS 17.6%