Node-RED - How to use the Visual Studio Code debugger

Published: | by Julian Knight Reading time ~2 min.
📖 Kb | 📎 Development | 🔖 node-red

Using the Visual Studio Code debugger to debug Node-RED issues

Originally from a thread in the Node-RED Google Group.

When using Visual Studio Code, the free code editor and Integrated Development Environment (IDE) from Microsoft to develop new nodes, it has an excellent built-in debugger. Since VS Code is built on Node.JS as is Node-RED, you can also use it to debug Node-RED issues.

  • Open the ~/.node-red (userDir) folder, click on the debugging sidebar and click on the cog icon which creates and opens a new file called launch.json in a folder called ./.vscode.

  • Add the following configuration to the .vscode file:

{% highlight javascript %} { “version”: “0.0.1”, “configurations”: [ { “type”: “node”, “request”: “attach”, “name”: “Attach to Process”, “processId”: “${command:PickProcess}” } ] } {% endhighlight %}

  • Start up Node-RED then click on the green “start debugging” icon in VSCode, you will get a popup to choose the active process you want to debug. All Node.js based processes will be listed. Pick the one that is Node-RED.

  • Having chosen, the debugger may pause things, if so, click on the continue icon or press F5.

To debug your own (or someone else’s) node, expand the “Loaded Scripts” list in the sidebar, find the appropriate script file, click on it to open. Now you can set breakpoints by clicking to the left of the line numbers.

When the execution hits a breakpoint, you will see the current call stack, variables and more.

I seriously wish that I’d got this working before because it is massively useful whether you are creating your own nodes or trying to track down performance or resource issues in your flows.

There are more VScode hints and information in the VSCode section of this site.


comments powered by Disqus