I’ve been asked for methods to debug nodes in Node-Red. Here is a brief introduction to this topic. This is very powerful and can save you time and energy when developing your flows.
- First we want to pull down the debug node and drop it into our flow. It will change to msg.payload once it is dropped in the flow.
- We can configure the debug node (msg.payload) settings or just leave it as the default. For this example we will just use the defaults.
There are a number of settings that you can configure and tweak given what output you are trying to see. I would encourage you to try out the different options to see what they do.
- Let’s link the nodes we want to debug so we can see the output. I am going to link every node to the debug node just to show you what it does but you can select just the specific one(s) you would like to see.
- Now click Deploy to save the changes.
- Let’s click the debug icon on the right-hand side to see what output was produced by our node.
Our flow in this case has produced 4 different results.
- The SQL statement being passed to the database node
- The result of the returned SQL results
- The result after it has been prepared in the function node
- The result that will be displayed
In my case the last node in this flow has been configured to show 2 icons; a red danger sign if the result = 1 and a green check mark if the result = 0. If we check the dashboard we will see the green check mark.
This is what is looks like from the dashboard view:
NOTE: If you do not have your flow set to inject once, then x. You can click the box to the left of the node to execute it.
Now, let’s see what happens with our dashboard when it is not populating a node
I am completely missing the Subsystem table now (it may still be showing if your browser cached it).
Let’s add the debug node to figure out why.
We can see by the output in the Debug window that the SQL statement is not valid. It gives us the SQL error and the statement that it tried to execute. Can anyone see the mistake?
Turns out I spelled distinct wrong, making the SQL statement not valid.
I hope this has helped you. Well that ends my brief into to debugging in Node-Red. Feel free to post your comments and questions below.