How to disable a tab at startup

Is it possible to enable/disable a tab at startup, with an environment variable ?
Something like this :

{
  "id" : "5f773146.6bf5",
  "type" : "tab",
  "label" : "Test",
  "disabled": "$env('DISABLE_TESTS')",
  "info" : ""
}
1 Like

Judging from this discussion I believe it is not currently possible to hide or disable specific tabs,
at least not in an easy way. Read through it though, it might help.
Jason.

@JayGhb that discussion is about dashboard tabs. The question here is about tabs, aka flows, in the editor

@jc-nr if it works, the syntax would be:

"disabled": "$(DISABLE_TESTS)"

which is how you can set any node property by environment variables.

However...

  1. I cannot remember if the environment variable handling is applied to tab nodes.
  2. If it does, I can't remember if the code will handle the value being a string rather than a Boolean

I'm out of the office this week so cannot look at the code on my laptop to give a more definitive answer.

So try it and see.... but based in the above, you may find it doesn't work.

Node-Red allows to access environment variables, within a flow, in a couple of ways. Check this link out:

Perhaps you could modify this flow from the library to achieve your purpose

https://flows.nodered.org/flow/7c67709fecce1ad5992b695028e57646

The idea of such flow is to use the value of an environment variable, for instance, COMPUTERNAME to gate (block or unblock) the message flow.

Testing

[{"id":"e310b11c.dcfc4","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"7a43bf4b.7d43b","type":"switch","z":"e310b11c.dcfc4","name":"Is this my computer ?","property":"$env(\"COMPUTERNAME\")","propertyType":"jsonata","rules":[{"t":"eq","v":"DESKTOP-PTRIO67","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":340,"y":240,"wires":[["763f0cbb.0a6cb4","f5a1884f.99a468"]]},{"id":"8b7a95a9.3d4598","type":"inject","z":"e310b11c.dcfc4","name":"my computer","topic":"","payload":"DESKTOP-PTRIO67","payloadType":"str","repeat":"6","crontab":"","once":true,"onceDelay":"","x":140,"y":240,"wires":[["7a43bf4b.7d43b"]]},{"id":"763f0cbb.0a6cb4","type":"function","z":"e310b11c.dcfc4","name":"Generate Random Data","func":"msg.payload = Math.round(Math.random()*100);\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":240,"wires":[["4db19f43.a8586"]]},{"id":"4db19f43.a8586","type":"debug","z":"e310b11c.dcfc4","name":"","active":true,"console":"false","complete":"false","x":790,"y":240,"wires":[]},{"id":"f15a9564.82bf78","type":"comment","z":"e310b11c.dcfc4","name":"Enable / Disable a Flow","info":"https://flows.nodered.org/flow/7c67709fecce1ad5992b695028e57646\n\n","x":160,"y":100,"wires":[]},{"id":"8be630f7.ed4fa","type":"change","z":"e310b11c.dcfc4","name":"Enviromental variables","rules":[{"t":"set","p":"a","pt":"msg","to":"COMPUTERNAME","tot":"env"},{"t":"set","p":"b","pt":"msg","to":"$env(\"COMPUTERNAME\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":420,"wires":[["3e88fb01.400b54"]]},{"id":"ff05f967.993978","type":"inject","z":"e310b11c.dcfc4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":420,"wires":[["8be630f7.ed4fa"]]},{"id":"3e88fb01.400b54","type":"debug","z":"e310b11c.dcfc4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":580,"y":420,"wires":[]},{"id":"f5a1884f.99a468","type":"debug","z":"e310b11c.dcfc4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":180,"wires":[]},{"id":"7f4cfa9f.82f8a4","type":"comment","z":"e310b11c.dcfc4","name":"Example: using environment variables in node change","info":"","x":260,"y":380,"wires":[]}]

I will give it a try, thanks!

@Andrei I'm using this approach yet. But it's not suitable for all use case (for example : the "e-mail in" builtin node).
I thought I could take advantage of the new property "disabled" of tabs.

@knolleary I tried the syntax, but you were right : the string is evaluated as a true expression and the tab is always disabled.

Maybe in another version...

@jc-nr, I suspected that but anyway the flow could be of use for someone else. In general how do you modify a property of the flow.json file (like disabled for instance) ? Do you do it programatically, using Node-RED API or at run time using a regular flow ? Let´s say you wanted to change another property, like label. How would you do that ? Thanks in advance.

@Andrei You mean at startup ?

This is still the case in 1.0.0

@knolleary, is there another way to do this?
I'm trying to disable / enable a tab by setting the enviroment variable in a balena.io deployed device.

Thanks

You could add something in your settings.js file that parses the env var to a boolean type:

if (process.env.MY_ENV_VAR === "false") {
   process.env.MY_ENV_VAR = false;
}

Hi Nick,
Do you mean inside module.exports = {} ?

No, it wouldn't be valid JavaScript inside the module.exports block. Put it at the top of the file.

It's still evaluated as "false"

Any other way around it?

It appears that process.env coerces anything you give it to a String.

The only other workaround would be to dynamically edit the flow file before NR starts to set the property as you want it.

1 Like

@scotie - How did you end up solving this?
In my case I want to disable some configuration nodes based on environment variables.