-
Notifications
You must be signed in to change notification settings - Fork 385
Debug container via Chrome Developer Tools
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!
-
Navigate to chrome://inspect in your Chrome browser.
-
Setup the IP address (of the host system where Node-RED is running), via the "Configure" button;
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!
-
Start the Node-RED container in debug mode (using the "debug" script).
-
In the server log, NodeJs will inform when he started listening to the debug port:
Debugger listening on ws://0.0.0.0:9229/...
-
As soon as NodeJs has started listening, an "Inspect" link will become available in Chrome below the IP address label:
-
After clicking that "Inspect" link, a Chrome Developer Tools window will be displayed:
-
Via Ctrl-P a Javascript file (e.g. of some node) can be selected:
-
As soon as the specified Javascript file is open, breakpoints can be added by clicking in the left bar:
-
In the top right of the window, some buttons are available to start/stop/pause... the program flow:
-
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.
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:
-
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 ...