Adding custom properties to a nodegen function node

Hey folks, I've just stumbled onto Node Red about a week ago and am having a lot of fun, thanks to IBM for the wonderful tool.

I'm looking to create a couple of custom nodes and this topic seems to have progressed quite a bit over the course of the beta versions and now to 1.0 with an automatic generator out in the wild. Sadly there are not a lot of step by step examples of custom nodes out there, and it seems that there's more than one way to go about this.

I've tested the nodegen application on a working rather complex function and it worked like a champ. So for the purpose of rapid development, does it make sense to use the nodegen app on an existing function and then just modify the nodegen output to add property choices? It seems to me from looking at the nodegen output that nodegen is just string-quoting my original function back to me, so to speak, to process its original logic with extra boilerplate stuff around it.

If that's the case, what's to stop me from simply modifying the HTML file to add the fields and variables I want, and then going into my original function string in the nodegen output and adding __node__.variable entries for each variable I defined in the HTML settings? Along with some if (!variable) defaults in that original function code for sane defaults if a bad setting gets past the HTML form validation?

It seems like the above would be the most pain-free way to rapidly turn functions into dynamic nodes.

Right now that it fairly much the best way if you want to start with a function and create a node. Once created you are free to edit it how you like to add extra capability. Of course it may be easier to just create a fully custom node as they aren't that hard to do if you know javascript etc. (it's just that nodegen ca do it in a minute :slight_smile:

Further down the line we are looking at creating exportable subflows - and these can already be configured more with things like environment variables and custom dialogues... but there is still a way to go before we get there.

Thanks, just wanted to make sure I wasn't missing some assumption under the hood that would cause that plan to fail.

I've written far more with plain ole Bash scripts and Python in the past few years doing purely synchronous things, so looking at Javascript doesn't immediately make the bells go off in my brain (yet). Having the generator will make the transition a lot easier, I think, because I don't have to worry about the particulars of the framework too and can just start off writing functions.

Being able to visualize the flow of everything makes async particulars way easier to grasp, I think this is a pretty good learning platform for those of us who have only ever worked with synchronous frameworks for that reason, too.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.