Friday, October 9, 2015

How to deploy a Hello World node.js app from your laptop to IBM BlueMix


I recently had the opportunity to begin learning IBM BlueMix.

To get started, I wanted to deploy a trivial Hello World program written in javascript/node.js.  And I wanted to do as many tasks as possible from the command line instead of the BlueMix web interface, because the web interface is useless for scripting and automation.

It wasn't easy.  I couldn't find complete and simple docs that worked.  Many docs I found were out-of-date, or focused on selling services.  It took me two days, working sporadically, to figure this out.  Thankfully, I found answers from bloggers (links included below).

The steps below worked on my Linux laptop (Ubuntu 12.04).  Mac should be similar.

I obfuscated my real email address to for privacy in the listings below.

Required:  Get yourself an account at IBM Bluemix.

Required:  Install the Cloud Foundy command line interface tool, cf, on your laptop.  Fetch it from  (as of this writing, I installed CF version v6.12.4, Linux 32-bit binary.)  Un-tar it and add it to your path.   IBM Doc: 

Recommended:  Install node.js on your laptop and add it to your path.  Reason:  It can be used to test the hello world locally on your laptop.

Part 1.  Prepare node.js app on your laptop

First create a node.js app and package.json file in the same folder on your laptop...

Create a new folder on your laptop for the app.

Create a file in that folder named hellohttp.js.  I found a trivial HTTP server app written by Tim Caswell.  Browse here and search for 'Hello HTTP':     Paste the contents into the file and save it.

Important: To support port mapping within BlueMix, edit the app to use environment variable VCAP_APP_PORT as shown below.  This code will listen on port 8000 on your laptop (where the env var is NOT defined), or on the BlueMix-defined port when deployed to BlueMix (where the env var IS defined)

    // Source:  Hello HTTP by Tim Caswell

    // Load the http module to create an http server.
    var http = require('http');

    // Configure our HTTP server to respond with Hello World to all requests.
    var server = http.createServer(function (request, response) {
      response.writeHead(200, {"Content-Type": "text/plain"});
      response.end("Hello World\n");

    // Listen on port VCAP_APP_PORT (if defined) or 8000 (default).
    var port = process.env.VCAP_APP_PORT || 8000;

    // Put a friendly message on the terminal
    console.log("Server running at" + port + "/");

Next create a file named package.json in the same folder as the hello http app.  Copy/paste the following content into the file.  Edit your personal info.

Note: The most important statement in this file is the scripts.start definition.  BlueMix issues this command to start your app.

I found this solution in a blog post by Brian Innes.  Brian documented several ways to start apps in BlueMix.
Of course, as soon as I discovered Brian's solution, I also found the package.json technique in the official docs:   Ugh.

      "name": "hellohttp",
      "version": "0.0.1",
      "description": "hellohttp",
      "author": "",
      "contributors": [
            {    "name": "myname",
                "email": "" }
      "scripts": {
        "start": "node hellohttp.js"

Local test

    If you installed node.js on your laptop, test the hellohttp.js app by running it locally.
            node hellohttp.js
        See response
            Server running at

            netstat -na | grep LIST | grep 8000
            tcp   0   0*   LISTEN

        Verify again
            Browse to http://localhost:8000, see response 'Hello World'.

Part 2.  Upload node.js app to BlueMix

From the same folder, issue these Cloud Foundry cf commands...

Set the API

    cf api

    Get response

        Setting api endpoint to
        API endpoint: (API version: 2.27.0)  
        Not logged in. Use 'cf login' to log in.

Log in

    cf login -u -o -s dev
        where -o is org, -u is username (both are the same when you first start using BlueMix), and -s is space dev.
    and enter your password when prompted

        Password> ********

    Get response

        Targeted org myname@example.comn
        Targeted space dev
        API endpoint: (API version: 2.27.0)  
        Space:          dev

Deploy the app.  The command 'cf push' will upload all files in your folder to BlueMix (recursively).

    cf push hellohttp

    Wait a few minutes to receive this entire response...

    Creating app hellohttp in org / space dev as
    Creating route
    Binding to hellohttp...
    Uploading hellohttp...
    Uploading app files from: /home/myname/sandbox/nodejs/hellohttp
    Uploading 1.1K, 2 files
    Done uploading              
    Starting app hellohttp in org / space dev as
    -----> Downloaded app package (4.0K)
    -----> IBM SDK for Node.js Buildpack v2.5-20150902-1526
           Based on Cloud Foundry Node.js Buildpack v1.5.0
    -----> Creating runtime environment
    -----> Installing binaries
           engines.node (package.json):  unspecified
           engines.npm (package.json):   unspecified (use default)
           Resolving node version (latest stable) via 'node-version-resolver'
           Installing IBM SDK for Node.js (0.12.7) from cache
           Using default npm version: 2.11.3
    -----> Restoring cache
           Loading 1 from cacheDirectories (default):
           - node_modules (not cached - skipping)
    -----> Checking and configuring service extensions before installing dependencies
    -----> Building dependencies
           Pruning any extraneous modules
           Installing node modules (package.json)
    -----> Checking and configuring service extensions after installing dependencies
    -----> Installing App Management
    -----> Caching build
           Clearing previous node cache
           Saving 1 cacheDirectories (default):
           - node_modules (nothing to cache)
    -----> Build succeeded!
           └── (empty)
    -----> Uploading droplet (14M)
    0 of 1 instances running, 1 starting
    1 of 1 instances running
    App started
    App hellohttp was started using this command `./vendor/initial_startup.rb`
    Showing health and status for app hellohttp in org / space dev as

    requested state: started
    instances: 1/1
    usage: 1G x 1 instances
    last uploaded: Wed Oct 7 15:11:49 UTC 2015
    stack: cflinuxfs2
    buildpack: SDK for Node.js(TM) (ibm-node.js-0.12.7)
         state     since                    cpu    memory        disk          details  
    #0   running   2015-10-07 11:12:56 AM   0.0%   55.2M of 1G   48.2M of 1G

    Determine the URL for your app.  Browse to the BlueMix web interface, look for your new app, and see the URL (in blue):

    Browse to the URL and see 'Hello World'.  For example, mine was:


It worked.  Claim success.


  1. Thanks Admin, I just begin my career in sever side web application development for that I complete the Node JS training but I wish to explore more in that, truly your blog provide some useful information and I would like to share your blog in my friends circle so keep sharing.
    Node JS training in chennai

  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Node JS Online Training from India . or learn thru Javascript Online Training from India. Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Online Training


Note: Only a member of this blog may post a comment.