# How to "switch off" specific flow functionality

**URL:** https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294
**Category:** General
**Created:** [5 July 2024 09:15 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294 "2024-07-05T09:15:26Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)
#### Post date: [5 July 2024 09:15 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/1 "2024-07-05T09:15:26Z")

</div>

Hi There,

I was wondering what is the best why to temporarily deactivate functionality within a flow?

Basically the scenario is a flow with a "production" representation and a "development" representation, each representation uses the same core functionality but production uses less of that functionality and has less debugging code. To have the production representation, I deactivate certain nodes thereby ensuring that specific parts of the flow are skipped, for example:

 ![Screenshot 2024-07-05 at 10.52.42](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/9/29e9f220ba5461eabbba393fd51982b483c7569f.png)

Here I skip the estimation of time and instead go direct to plotting some data. I sometimes use the estimation in development, so there is a reason why it's there.

Of course there are a number of ways to deal with this scenario:

1. create two distinct copies of the flow and maintain the two. The repetition of code here makes this solution if viable for me.

2. add switch nodes that refer to a global environment variable, something like `if global.env.state == production ...`. I'd prefer the switch variation but the problem is that it's a switch node and it's not simple to see what it does or that it refers to a global value. (for me: this kind of "representation switching" is a "compile" time feature and the switch node doesn't make this clear). Also having to set global environments isn't that obvious (they don't tend to be visible in node-red) and setting them isn't that simple.

3. disabling nodes that should be skipped (as in the diagram). The disadvantage of the enable/disable nodes is that it's just one node of a flow (see above) and it's unclear that the rest of the flow (i.e. downstream) is also disabled. Also it is not clear why the node is disabled in the first case.

4. ... better options?

Edit: To make it more clear what happens in that flow, here a "refactored" version:

 ![Screenshot 2024-07-05 at 11.17.15](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3a4549e4b43134ca8f8313e43d40bcb391a867d7.png)

now it's a bit clearer what happens when the node is disabled.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [5 July 2024 09:52 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/2 "2024-07-05T09:52:45Z")

</div>

Maybe adding a msg property to your flows that distinguishes the development or production run. Then the switch nodes in option 2 could act on this property, which may be clearer to see why the switch is there, and no context to set or maintain, just change the msg property at start of flow in a change node labeled clearly. Or the change node could set the context value.

---

<div class="post-metadata">

### Author: ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)
#### Post date: [5 July 2024 10:13 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/3 "2024-07-05T10:13:31Z")

</div>

Could you use a gate/s with the status shown and activated by a global variable to alter the path/s through the flows?

---

<div class="post-metadata">

### Author: ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)
#### Post date: [5 July 2024 10:52 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/4 "2024-07-05T10:52:22Z")

</div>

> [@mudwalker](#):
>
> Could you use a gate/s with the status shown

that's what I am kinda of thinking - something that visually makes it clear which flow is taken.

Potentially it has the same issues as disable/enable: you only see the gate and have to look on to see the downstream nodes that are also "bypassed", i.e. disabled.

BTW this would also be useful for A/B testing whereby two different features are compared by activating one feature for X % of end customers and the other feature for (100 - X) % of end customers. Then conversion (or whatever is the KPI) is compared across the features.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [5 July 2024 11:12 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/5 "2024-07-05T11:12:57Z")

</div>

You could have two distinct copies in the same flow, as two groups "Production" and "Development".

You can disable an entire group with "Disable selected nodes", though there is no default keyboard shortcut for it and it's not in the right click options.

---

<div class="post-metadata">

### Author: ![arturv2000](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arturv2000/32/88724_2.png) [@arturv2000](https://discourse.nodered.org/u/arturv2000)
#### Post date: [5 July 2024 11:23 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/6 "2024-07-05T11:23:54Z")

</div>

What I do in my case, is to use GIT and two node-red instances.

I have a Development and Production instances, and use GIT to transfer / update the flows between the instances, normally always from Development to Production.

Also have defined in `settings.js` a variable that indicates if it is the production or development instance, and based on this variable have `switch` and checks in some `function` nodes to allow or disable some flow / ui functionalities.

Also use this as simple / complicated way to limit the data that some users / instances can see on the UI.

---

<div class="post-metadata">

### Author: ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)
#### Post date: [5 July 2024 12:16 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/7 "2024-07-05T12:16:24Z")

</div>

> [@arturv2000](#):
>
> I have a Development and Production instances, and use GIT to transfer / update the flows between the instances, normally always from Development to Production.

Yep that's the way it should be and perhaps my use-case is somewhat unusual. In my case this is a hobby project that only has one instance, so it's harder to split up flows.

> [@jbudd](#):
>
> You can disable an entire group with "Disable selected nodes",

true using groups for this would also be a good alternative.

One off-the-wall idea that I just had was to take concepts from graphic manipulation programs, e.g. gimp and photoshop. I've been doing a lot of graphics recently and one thing I use quite often are masks and layers. This gave me the idea (just now) that if there was a mask that I could overlay over my entire flow and use that mask to disable certain nodes (that's what masks do - they hide stuff). A layer concept would be showing or hiding certain nodes or section/groups of nodes - hiding would be the same as disabling.

Visually it could look a lot like the visual node selector, e.g. when using the catch node:

 ![Screenshot 2024-07-05 at 14.13.20](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/97bd74bf10fe58a7eb9452e3058640a2b6549f5d.jpeg)

I would really enjoy a feature like that 😉 And it would definitely make Node-RED become a cross-over development tool between visual manipulation and textual coding manipulation!

---

<div class="post-metadata">

### Author: ![DiverRich](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/diverrich/32/64523_2.png) [@DiverRich](https://discourse.nodered.org/u/DiverRich)
#### Post date: [5 July 2024 21:48 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/8 "2024-07-05T21:48:28Z")

</div>

Not sure if this is particularly helpful for your application, but I use [node-red-contrib-switch-break](https://flows.nodered.org/node/node-red-contrib-switch-break) when I need to shut down certain aspects of my flows; such as ignoring a motion sensor. Works very well for that. I typically trigger mine with voice commands.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 July 2024 07:47 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/9 "2024-07-06T07:47:29Z")

</div>

> [@DiverRich](#):
>
> [node-red-contrib-switch-break](https://flows.nodered.org/node/node-red-contrib-switch-break)

I don't know that node, but I use [node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate).

---

<div class="post-metadata">

### Author: ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)
#### Post date: [6 July 2024 08:25 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/10 "2024-07-06T08:25:09Z")

</div>

> [@DiverRich](#):
>
> node-red-contrib-switch-break

> [@Colin](#):
>
> [node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate).

Thanks for the tips and both are going in the direction I was thinking, especially the switch-break node. It seems to be able to control multiple breaks via one director, which is what I am looking for. Plus it has the centralised director which is lacking in the simple-gate node.

One improvement I could think of is to have a fork gate that directs traffic to one flow or another, i.e. a gate node with multiple outputs - a kind of fixed switch node ...

---

<div class="post-metadata">

### Author: ![DiverRich](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/diverrich/32/64523_2.png) [@DiverRich](https://discourse.nodered.org/u/DiverRich)
#### Post date: [6 July 2024 20:43 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/11 "2024-07-06T20:43:45Z")

</div>

> [@gregorius](#):
>
> One improvement I could think of is to have a fork gate that directs traffic to one flow or another, i.e. a gate node with multiple outputs - a kind of fixed switch node ...

You're right about this. I'm able to accomplish something like that with and/or gates and the occasional function node, but your suggestion would really improve and simplify things.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [6 July 2024 22:07 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/12 "2024-07-06T22:07:19Z")

</div>

> [@gregorius](#):
>
> a gate node with multiple outputs - a kind of fixed switch node

Could perhaps my [node-red-contrib-msg-router](https://flows.nodered.org/node/node-red-contrib-msg-router) be of any help?

---

<div class="post-metadata">

### Author: ![KSum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ksum/32/78579_2.png) [@KSum](https://discourse.nodered.org/u/KSum)
#### Post date: [8 July 2024 23:53 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/13 "2024-07-08T23:53:22Z")

</div>

I use the [node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate) for this and open/close the gate to different sections. The included examples are good to get you using it.

---

<div class="post-metadata">

### Author: ![berijan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/berijan/32/35313_2.png) [@berijan](https://discourse.nodered.org/u/berijan)
#### Post date: [10 July 2024 11:04 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/14 "2024-07-10T11:04:16Z")

</div>

Have you thought about using Node-Red subflows for the common part of the functionality. When using subflows you don't have to duplicate code for example if you make different flow for development and production.

[https://nodered.org/docs/user-guide/editor/workspace/subflows](https://nodered.org/docs/user-guide/editor/workspace/subflows)

---

<div class="post-metadata">

### Author: ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)
#### Post date: [10 July 2024 13:36 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/15 "2024-07-10T13:36:22Z")

</div>

> [@KSum](#):
>
> I use the [node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate) for this and open/close the gate

> [@BartButenaers](#):
>
> Could perhaps my [node-red-contrib-msg-router](https://flows.nodered.org/node/node-red-contrib-msg-router) be of any help?

I decided on switch-break because that has a centralised switch mechanism, so I have two directors (development and production) and a number of actors that are controlled by the directors. That provides the centralisation I was looking for.

> [@berijan](#):
>
> Have you thought about using Node-Red subflows

I avoid subflows preferring custom nodes for encapsulating functionality. Subflows are good for specific use cases but I generally try to work around them. I recently discovered [flow-manager](https://flows.nodered.org/node/node-red-contrib-flow-manager) that makes working subflows more transparent - I might have a look at that.

---

<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: [8 October 2024 13:36 UTC](https://discourse.nodered.org/t/how-to-switch-off-specific-flow-functionality/89294/16 "2024-10-08T13:36:41Z")

</div>

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