Request for Help/Ideas with Subflow Management

One of the reasons I like to use subflows in my projects is to make reusable chunks of functionality. However, I'm really struggling to effectively manage my subflows across different projects, especially if a subflow contains another subflow. I'm running into all kinds of version and duplication problems: If I enhance the subflow in one project, it is not at all straightforward to update the other projects to include these enhancements. But even that aside, even just importing the various subflows (again, especially if a subflow contains another subflow), I invariably end up with many duplicate copies of the subflows in my projects. By manually searching and replacing the node files I can "reconverge" the various copies on to a single subflow once again, but it is fairly tedious and easy to bungle.

I can't believe that I'm the only one who keeps bumping into this problem... Can anyone share what they are doing manage the situation and perhaps be more successful than I've been so far in reusing subflows across projects?

Thanks!

1 Like

Have a look at this PR I raised yesterday for the 1.2 release.

It makes it possible to update a subflow when you import something you already have.

2 Likes

Personally, I don't have a lot of overlapping flows between different instances of Node-RED (I don't currently use projects). However, where I do want to reuse code, I will export to the library and copy from there then import.

That doesn't really help you with version management though I know.

Have you considered converting some subflows to code and creating a private node or set of nodes? That way you can use standard coding practices to manage them?

Love that idea. Thank you! That would prove extremely helpful. It sounds like it would be able to identify subflow as a duplicate even when it is imported as a subflow embedded in the subflow you are importing?

If my subflows could act just like other nodes one imports into the palette, that would be ideal... I've seem some buzz around a tool that would convert subflows to regular nodes (the name escapes me at the moment), but it didn't strike me as something that was making much progress.

I'm not familiar with how one would convert a subflow to code? Are you suggesting that I actually write JS that does the same thing my subflow is designed to do and then package that as a node? Or is there actually a tool to help facilitate subflow -> code conversion?

Once converted to code, I'm guessing it would not convert back to nodes easily... However, I think I could easily work around that either by editing the code directly or always editing the subflow as nodes before converting to code... Thanks!

Yes, I think that the guys from Hitachi wrote something but I've not tried it I'm afraid.

Yes, use the subflow as a prototype and convert it. Common chunks of code can be put in a shared library. The rest put into 1 or more custom nodes.

You would encapsulate your code in a custom node. It isn't hard to create a custom node and you don't have to publish is unless you want to, it is easy to install from GitHub for example.

It will work best if you aren't constantly tweaking your code. However, if it were only you using the code, that is easy enough too. Just remember that you have to restart Node-RED to pick up any changes. If you are running Node-RED manually, you can configure PM2 or nodemon to run Node-RED and listen for changes so that it restarts Node-RED automatically.

1 Like

Cool. Thank you for the ideas!

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