Skip to content

Debug container via Chrome Developer Tools

bartbutenaers edited this page Feb 9, 2020 · 1 revision

The readme page describes how a Node-RED container can be started in debug mode. This means the NodeJs server will start listening to debug port 9229, for any debugger client to connect.

Various debugger clients can be used, to debug the server-side code of your Node-RED application (running in a Docker container). But this tutorial only will explain step-by-step how to use the Chrome debugger.

Remark: the steps below can also be used for a Node-RED application which is running without Docker!

Debugging using the "debug" script

  1. Navigate to chrome://inspect in your Chrome browser.

  2. Setup the IP address (of the host system where Node-RED is running), via the "Configure" button;

    Setup IP

    This only needs to be done ONCE! Multiple IP addresses can be added, but be aware that this page will take a long time to load when one or more of these IP addresses cannot be reached by Chrome!

  3. Start the Node-RED container in debug mode (using the "debug" script).

  4. In the server log, NodeJs will inform when he started listening to the debug port:

    Debugger listening on ws://0.0.0.0:9229/...
    
  5. As soon as NodeJs has started listening, an "Inspect" link will become available in Chrome below the IP address label:

    Inspect link

  6. After clicking that "Inspect" link, a Chrome Developer Tools window will be displayed:

    Developer tools

  7. Via Ctrl-P a Javascript file (e.g. of some node) can be selected:

    Js selection

  8. As soon as the specified Javascript file is open, breakpoints can be added by clicking in the left bar:

    Breakpoint

  9. In the top right of the window, some buttons are available to start/stop/pause... the program flow:

    Controls

  10. As soon as NodeJs executes the statement with your breakpoint, the debugger will break at that statement and you can start debugging ...

There is much more to tell about the Chrome Developer Tools, but that is outside the scope of this tutorial.

Debugging using the "debug_brk" script

The problem with the "debug" script is that you are not able to debug the Node-RED startup code. Indeed the application startup goes very quick, which means you have not time enough to setup your breakpoints. In that case the "debug_brk" script can be used.

All required steps are the same as listed above! But after step 4, NodeJs will break automatically. Which means your Node-RED application won't be started immediately! Instead NodeJs will start waiting, until a debugger client connects:

  • Indeed when (via the "Inspect" button) a Developer Tools Window is opened, the debugger will automatically show that the application flow is paused at the first statement of the Node-RED application:

    First statement

  • Now you can add breakpoints and start debugging ...

    Remark: when using Ctrl-P you will notice that not all Javascript files are available yet (e.g. no code for Node-RED nodes). Reason is that Node-RED hasn't loaded those files yet at this moment ...