# Custom node vs subflow

**URL:** <https://discourse.nodered.org/t/custom-node-vs-subflow/49434>\
**Category:** Developing Nodes\
**Created:** [6 August 2021 19:47 UTC](https://discourse.nodered.org/t/custom-node-vs-subflow/49434 "2021-08-06T19:47:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dczysz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dczysz/32/46158_2.png) [@dczysz](https://discourse.nodered.org/u/dczysz)\
**Post date:** [6 August 2021 19:47 UTC](https://discourse.nodered.org/t/custom-node-vs-subflow/49434/1 "2021-08-06T19:47:09Z")

</div>

I currently have a function node to dynamically generate a filename which gets passed to the file out node as `msg.filename`. I made each version - a subflow of the function node + file out node, and a custom node that is basically just the function node. In this case it seems to make the most sense to do a subflow, since then I can wrap both nodes up into one.

But I have another function node used multiple places that reads from a file (on its own, not with a file-in node) and adds some extra stuff to the `msg`. For this simpler case, where would you draw the line between making a single node subflow vs a custom node for something like this? Are there performance reasons to use one over the other if in the end it's basically just a function node wrapped up as either a subflow or custom node?

---

<div class="post-metadata">

**Author:** ![rakgupta](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rakgupta/32/42535_2.png) [@rakgupta](https://discourse.nodered.org/u/rakgupta)\
**Post date:** [6 August 2021 20:22 UTC](https://discourse.nodered.org/t/custom-node-vs-subflow/49434/2 "2021-08-06T20:22:31Z")

</div>

> [@dczysz](#):
>
> For this simpler case, where would you draw the line between making a single node subflow vs a custom node for something like this

May not be directly related to your use case, but I have a couple of "single node" sub-flows (email node, pushover node) to avoid having to enter credentials multiple times. These nodes do not have a "config" node and each instance requires the same credentials, so it just makes it simpler to have them in a sub-flow and use it wherever needed.

---

<div class="post-metadata">

**Author:** ![dczysz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dczysz/32/46158_2.png) [@dczysz](https://discourse.nodered.org/u/dczysz)\
**Post date:** [6 August 2021 20:35 UTC](https://discourse.nodered.org/t/custom-node-vs-subflow/49434/3 "2021-08-06T20:35:08Z")

</div>

Thanks for the input. So I guess it kind of depends on whatever works best for my use case then. The goal is really to just eliminate duplicate function node code, since this is/will be used in about 10-20 places in various flows.

---

<div class="post-metadata">

**Author:** ![rakgupta](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rakgupta/32/42535_2.png) [@rakgupta](https://discourse.nodered.org/u/rakgupta)\
**Post date:** [6 August 2021 20:49 UTC](https://discourse.nodered.org/t/custom-node-vs-subflow/49434/4 "2021-08-06T20:49:40Z")

</div>

> [@dczysz](#):
>
> The goal is really to just eliminate duplicate function node code, since this is/will be used in about 10-20 places in various flows.

I guess the trade-off is one is easy to maintain (sub-flow - changes in one place only) and the other is easier to customize (repeated code - easier to tweak for a particular use case).

---

<div class="post-metadata">

**Author:** ![MyRandomThoughts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/myrandomthoughts/32/41085_2.png) [@MyRandomThoughts](https://discourse.nodered.org/u/MyRandomThoughts)\
**Post date:** [6 August 2021 21:03 UTC](https://discourse.nodered.org/t/custom-node-vs-subflow/49434/5 "2021-08-06T21:03:07Z")

</div>

If you have a input only flow (like rakgupta's pushover, which I also have) I use a Link-In/Link-Out type flow where I have my pushover node connected to a Link-In and function nodes for message formatting. I can then send any flow to it.

Stuff like that I have in its own little group and on a tab page for other like-minded flows.

Going the other way, on that same tab page, I have a group for all my timers that Link-Out to all my other flows:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c0713e2304ed78d48fae741b3ec47a296fcd638a.png)

---

<div class="post-metadata">

**Author:** ![dczysz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dczysz/32/46158_2.png) [@dczysz](https://discourse.nodered.org/u/dczysz)\
**Post date:** [6 August 2021 21:03 UTC](https://discourse.nodered.org/t/custom-node-vs-subflow/49434/6 "2021-08-06T21:03:59Z")

</div>

> I guess the trade-off is one is easy to maintain (sub-flow - changes in one place only) and the other is easier to customize (repeated code - easier to tweak for a particular use case).

Yeah that's something I've been trying to keep in mind, like using the sub-flow environment variables to allow for _some_ customization.

I'll do some more thinking/planning and see where we end up.

Thanks again for all your help!

---

<div class="post-metadata">

**Author:** ![dczysz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dczysz/32/46158_2.png) [@dczysz](https://discourse.nodered.org/u/dczysz)\
**Post date:** [6 August 2021 21:11 UTC](https://discourse.nodered.org/t/custom-node-vs-subflow/49434/7 "2021-08-06T21:11:30Z")

</div>

> [@MyRandomThoughts](#):
>
> Going the other way, on that same tab page, I have a group for all my timers that Link-Out to all my other flows

Hmm that's interesting, I haven't used (or even looked into) link nodes at all. That could probably come in handy for trimming down our huge amount of global variables at least.

---

<div class="post-metadata">

**Author:** ![MyRandomThoughts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/myrandomthoughts/32/41085_2.png) [@MyRandomThoughts](https://discourse.nodered.org/u/MyRandomThoughts)\
**Post date:** [6 August 2021 21:16 UTC](https://discourse.nodered.org/t/custom-node-vs-subflow/49434/8 "2021-08-06T21:16:48Z")

</div>

I use them a lot, it's very helpful for passing data between tabs or groups of nodes in a clean way. I am very OCD when it comes to making sure the flow is easily readable and not having random lines all over the screen 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 October 2021 21:17 UTC](https://discourse.nodered.org/t/custom-node-vs-subflow/49434/9 "2021-10-05T21:17:44Z")

</div>

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