As my Home Assistant Node-RED project is becoming bigger, I am looking for better ways to manage my flows and, in particular, the javascript from my function nodes. I'm impressed that Node-REDs javascript enables classes, arrow functions, promises and more (but apparently is still using require
rather than import
and export
?).
node-red-contrib-flow-manager does exactly what I want for flows. But I still find how I manage my js code to be a bit awkward.
Code inside of json or YAML flow files is one awkwardness. A bigger one is where to put, and how to include, common code and large class definitions. [At present I'm attaching my common functions as properties of an object that I set on the global object (no code completion when I use these functions), and in-lining class definitions within the functions where they are used.]
Maybe there are better existing code management strategies that I don't know about? One is to attach common code to settings.js
but that doesn't seem to make it any cleaner, and then forces a node-red restart if you change the code (?). Admittedly I haven't investigated creating custom nodes for every one of my function nodes, as that seems a bit extreme.
It would be nice if the functions' js code was split out into separate files, rather than all being inside flow files. This would be better for
- editing purposes (use vs-code, even though the built-in editor is good),
- version control
- and possibly:
- would allow importing common code (via
export
andimport
) that could be imported at deploy time. - code generation from TypeScript
- an easier debugging setup?
- would allow importing common code (via
Any thoughts or suggestions?