Hey Steve,
Thanks a lot for the tip
At the time being this was not possible. But seems that since NodeJs version 8.4.0 it is indeed possible to attach a remote debugger to a vm context. What a pity that I haven't tried it anymore meanwhile...
Here are the steps to debug a function node via the Chrome debugger:
-
You need to configure ONCE the IP address of your Node-RED server, via
chrome://inspect
:A. Click the 'Configure' button
B. Enter<ip address Node-RED server>:9229
C. Click the "Done" buttonRemark: if you are running Node-RED on multiple devices, you can specify here all their IP addresses. But I wouldn't do that because - when one of the Node-RED instances is not accessible - Chrome will keep trying to access it, resulting in long waiting times...
-
Enter a
debugger;
statement in your function node code: -
Start your Node-RED server in debug-mode (which means it is allowed to attach a debugger process), e.g. on Linux:
node --inspect=0.0.0.0 /usr/bin/node-red
Remark: for those who don't know where there Node-RED has been installed, you can find it like this on Linux:
Remark: for those who want to debug the startup code of Node-RED, you need to use this command:
node --inspect=0.0.0.0 --inspect-brk /usr/bin/node-red
-
Node-RED will start now, and NodeJs allows a debugger process to attach:
-
Now Chrome should see that the debugger can be attached:
A. Chrome will show your server
B. Chrome will show an "inspect" link -
After clicking the "inspect" link, a Chrome developer console window will open. You will arrive in the debugger at your function node:
Remark: it could be that the debugger stops at another debugger statement of another node (e.g. another developer forgot to remove a debugger statement). Just use F8 to unpause the debugger and let it run to the next debugger statement (or breakpoint).
-
Now you can step through your code (via the navigation buttons on the top right), show content of variables (on the lower right), and so on...
Remark: it is also possible to debug other nodes, by pressing
Ctrl-P
, and then selecting the node that you need: -
Click on a line number to add a breakpoint, where your debugger needs to stop:
Although Visual Studio code offers much more functionality, for lots of users it might be easier to start with the Chrome debugger I think ...
Have fun with debugging your function node!
Bart