Best practice: custom v. function node

And that is one of the reasons it exists of course. Node-RED is a general purpose low code development tool. It can be used for all manner of things and by all manner of people with different experience levels.

As a reasonably experienced JavaScript programmer, I often find things much easier to accomplish in a function node than having to use a bunch of other nodes. Though I might experiment with a flow using nodes and after a year or so get fed up with the number of nodes cluttering the screen so wrap them all up into a function node or two. I also regularly find myself using function nodes as simple wrappers around 3rd-party libraries - especially for things like CSV/Excel file handling.

So I'll use Node-RED both as a prototyping platform and as a live platform because I'm too lazy to faff with all the boilerplate code likely to be needed to stand up even a simple microservice using Node.js or Python.

But of course, for many, people, it is the simplicity of the node-and-wire based approach - avoiding code completely - that attracts them.

And for all of us, having access to thousands of specialist nodes that wrap up a level of complexity, makes life very easy. This is one of the reasons that I wrote UIBUILDER. To hide most of the complexity of dealing with the DOM and with 2-way, realtime communications between the client and the server. But without having to commit to an equally complex front-end framework with all its own quirks and issues and that takes you away from learning about vanilla HTML/CSS/JavaScript so leaving you at the mercy of the development of the framework. UIBUILDER is therefore, I suppose, like the function node of web development in Node-RED. :grinning:

Anyway, coming back on-topic. BOTH custom nodes and function nodes have their - well defined - place in the Node-RED universe.

However, what I would say, now that I've a number of complex custom nodes under my belt, is that developing nodes, while fairly straight-forwards, is time consuming, very time consuming in fact. And on this note, I've been playing with some ideas on how the time and complexity to create custom nodes could be reduced. See some of those ideas taking form in An idea for third-party UI in ui-builder - Developing Nodes - Node-RED Forum (nodered.org). Where I start to try and go beyond uibuilder to think about how the experience could be improved for all.

Anyway, that is a different topic so I'll stop here.

2 Likes