ActiveBlog

Debugging Node.js Applications in Stackato
by Ho Ming Li

Ho Ming Li, November 13, 2013

Node.js Debugging Let’s face it, there will be bugs...in my applications and yours. From println/echo debugging to using full-on debuggers, a developer will no doubt spend a portion of his or her time debugging applications. By now, most developers are familiar with the various debugging tools in their local development environment, but as they step towards cloud deployments, how can they achieve the same? Is remote debugging even possible in the cloud? Well of course it is.

We have seen earlier how to debug Java applications in Stackato using the Harbor service. Recently I asked whether or not we can debug Node.js applications in Stackato, and so I took a look at node-inspector.

Straight from the project's README file, "Node Inspector is a debugger interface for node.js using the Blink Developer Tools (former WebKit Web Inspector)."

Without further ado, here are the steps for setting up node-inspector to debug a Node.js application. We'll use haste-server as an example.

Note: The commands in this article are for Stackato version 2.10.6 (based on Cloud Foundry v1). Some of the commands and app config will be slightly different using Stackato 3.0.

  1. Make sure to include node-inspector in your package.json:

        "dependencies": {
        "winston": "0.6.2",
        "connect": "1.9.2",
        "redis-url": "0.1.0",
        "redis": "0.8.1",
        "uglify-js": "1.3.3",
        "node-inspector": "0.5.0"
      },
  2. Change the default stackato.yml config file to add a Harbor port service and a --debug flag to the command used to start the server:

      name: hastebin
      mem: 128M
      services:
        file-backing: redis
        debug-port: harbor
      processes:
        web: node --debug server.js
  3. Target the client, authenticate, then push the application code and config:

      $ stackato target api.stackato-demo.local
      ...
      $ stackato login
      ...
      $ stackato push -n
  4. Once the app is running, SSH into the app container and run node-inspector with the port number returned by $STACKATO_HARBOR:

      $ stackato ssh hastebin
      hastebin.stackato-demo.local:~$ node-inspector --web-host 0.0.0.0 --web-port $STACKATO_HARBOR
      Node Inspector v0.5.0
       info  - socket.io started
      Visit http://0.0.0.0:4100/debug?port=5858 to start debugging.
  5. From the local machine, find out the external Harbor port:

      $ stackato service debug-port | grep port
      debug-port
      | - port      | 39023                                                 |
      | - tags      | harbor harbor-1.0 {Persistent external ports service} |
  6. Open browser and navigate to http://<app url>:<ext-harbor-port>/debug?port=5858

    node-inspector

  7. With the Harbor port service available in Stackato, you can now easily debug your Node.js application running in the cloud with node-inspector. However, like any other awesome feature, it is not without its caveats. In order to run node-inspector, be prepared to increase the memory limit for the application as overhead for the debugger. Also, this approach is for debugging a single instance Node.js application - when scaled out to multiple instances, things can get a little more complicated.

    If you are a developer with a Node.js application that you want to move to the cloud, download the Stackato microcloud and give it a try.

    Subscribe to ActiveState Blogs by Email

    Share this post:

Category: stackato
About the Author: RSS

Ho Ming Li joined ActiveState as a Sales Engineer. He has diverse experience in the software industry with past roles in development, quality assurance, release management, and professional services. With education in both technology and businesses, he aspires to be a tech guy with business sense, aiming to deliver business solutions through awesome tech products. When he is not in front of a computer, he plays a variety of sports and enjoys the outdoors.