Warning: count(): Parameter must be an array or an object that implements Countable in /home/iteanz/public_html/wp-includes/post-template.php on line 317

3. Debug a Node.js application

In this section, you will repeat the previous steps with a similar application except that this application is running on the IBM SDK for Node.js in Bluemix. This example will show you how to enable debug and development mode by modifying the manifest file when you push an application to Bluemix.

IBM Bluemix DevOps Services web user interface also provides another way to activate development mode for Node.js applications as shown in this diagram:

For this section, you will focus on the basics: using a text editor, cloud foundry CLI, Bluemix Live Sync, and the node inspector running in Chrome. Again, you’ll see the steps to start from the beginning, but if you have an existing Node.js application to work with, you can skip or review steps 1 – 3.

  1. Go to the Bluemix Catalog, select Boilerplates, and then click the Node.js Cloudant DB Web Starter boilerplate.
  2. Enter a unique name for the application. In these examples, you will see an application named cadc-nodecloudant-ws16. You should use a different name and do not use an underscore in the name. Keep the remaining defaults in the boilerplate and click Create.
  3. From the Bluemix dashboard, navigate to the new application. To download the sample code for the application, click the Getting Started link. Scroll down and click Download Starter Code to download the application starter code to your workstation.
  4. Extract the starter code on your workstation to a directory. Work from this directory and edit the package.json file. Verify that this file contains a start command for the application so that the Bluemix application management utilities can be properly configured by the buildpack.
  5. Edit the manifest.yml file: add 128M to the memory for the application 
  6. Clear any cached state of the application that might prevent the application management tools from starting by removing the application by using the Bluemix plugin and repush the application. If the Bluemix plugin is not installed on your machine, download and install from http://clis.ng.bluemix.net/ui/home.html

    $ bx login api
    $ bx cf delete cadc-nodecloudant-ws16
    $ bx cf push
    $ bx cf set-env cadc-nodecloudant-ws16 BLUEMIX_APP_MGMT_ENABLE devconsole+shell
    $ bx cf restage cadc-nodecloudant-ws16

  7. After the application is started, to start a connection to the development support console, open the URL. Use the name of your application in the URL: https://cadc-nodecloudant-12ws16.mybluemix.net/bluemix-debug/manage.  Then, authenticate with your IBM id when prompted

  8. From the application management console, open a shell in the container that is running your application.
  9. Optional: Launch the node inspector, which requires the Chrome browser, from the application management console by selecting Open Debugger. After you open the debugger, place a breakpoint at line 189 in the app.js file as shown:
  10. Go to the home page for the starter application and upload a file. This will trigger the breakpoint and you can step through the code, inspect variables, or restart the application with the F8 key (or Resume button). Add more breakpoints and experiment. Then, disable all breakpoints and close the node.
  11. Disable debugging by reducing the memory that you added to the application in the manifest.yml file.
  12. Update the application by running the followin commands
    $ bx cf set-env cadc-nodecloudant-ws16 BLUEMIX_APP_MGMT_INSTALL false
    $ bx cf restage cadc-nodecloudant-ws16



You should now understand how to enable remote debugging for IBM Java Liberty runtime and IBM Node.js runtime applications by using development mode and be able to update a live application without a full redeployment.