Hi folks,
I'm into node-red for some weeks now and one problem keeps coming up again and again for me.
I have a dozen sequences and multiple flows/tabs and the nodes in there shall rely on specific settings I want to maintain in a single place (or for each flow/tab separately).
So I like to set the email server, mqtt-prefixes, watch folder paths, http-endpoint uris etc. in a dedicated "config" location and pick bits out of the config via function node e.g., but most nodes do not seem to support injecting required properties via msg (which I use whenever possible). I even went as far as writing a custom "watch" node, which is able to be read folder-paths to watch at from msg.filepath, but I obviously cannot come up with custom nodes for all the native nodes in node-red just to make configuration possible.
What I am basically looking for is something like this:
- inject object like { myProject : { emailserver : "mymail.com" }} into global context at flow startup.
(I seem to have accomplished this with "node-red-contrib-config" at least.)
- enter {global['myProject.emailserver']} as "Server" value in the email-node editor (e.g.)
(This would also avoid "useless" setup/change/function nodes on front of many nodes.)
Is there something like this?
Thank you! o)
ps: I've seen that you can use ENV vars like this, but maintaining ENV vars for the project externally is not really the way to go in my opinion and I have hundreds of configurable items (ip-cameras, ip-addresses, folders, etc). I cannot list or edit ENV vars from within the node-red environment in a "settings-container" like fashion easily either.
You can do the first part using an object node and the basic change node where you can set
a global variable to be an object. No need for any contrib nodes
This is exctly what I use global contect variables for. You have tab 1 (I rename the tab to 'Initialize') the place you set the variables and then the other tabs can grab the values when they need to use them.
If you really do mean you want to do it at startup time - then you can use environment variables - https://nodered.org/docs/user-guide/environment-variables
Or in the globals section of the settings.js file. To make management easier, you can leverage the node.js modules feature to create your own single-file module that you can then require into the globals. That way you can keep your own settings in your own file.
Hello guys, thank you for helping out! o)
First point is kinda solved with "node-red-contrib-config"? Let me quote from its page (https://flows.nodered.org/node/node-red-contrib-config):
If the Config node is Active, the configuration properties will be applied at startup before any flows are started.
Having the settings ready before the flows start is quite important, I was just looking for an alternative to the contrib node. Using settings.js is difficult, settings in there do not export well together with the flows.
Regarding 2) Any ideas here? This is the real difficulty. How to supply settings to nodes, which do not support incoming msg. As mentioned, I had hopes to be able to use the node editor with some curly-bracket syntax or something to inject settings, like it's possible with ENV vars.
Today, env var are the only option available to do this sort of thing.
As of 1.0, it is possible to define and manage env vars within a subflow, but not generally.
There are some thoughts about adding something to the projects feature to make it possible to manage settings for different environments. But they are only thoughts and there's no specific plan to deliver it.