FAQ 1: Should I use a function node or a flow of core nodes?

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

There are usually many ways to achieve something in Node-RED. A common question is whether or when to use a function node or a collection of core nodes to achieve an outcome.

Whether I use one approach or the other depends on the complexity of the input vs the complexity of the output. It really doesn’t matter except that it is often easier to read a single function node that several complex change nodes as an example.

So my general rules of thumb for whether to replace a collection of nodes with a function node are:

  • How difficult would this be to do in a pure flow? If it is just a couple of nodes, that’s fine, if it is 10 nodes then probably not fine.
  • If I am using JSONata, how long is it taking me to puzzle over the JSONata code? If it is a few minutes then fine, otherwise use a function node!
  • Did someone already write some JavaScript that I can purloin? If so then use it!

Of course, I know JavaScript reasonably well and if you don’t then your own rules might look a little different.


comments powered by Disqus