Changing node configuration using external methods

In my project I use multiple libraries that have access to external devices through IP address. The problem I got is that every time I need to change to another device that has different IP address I need to change multiple config nodes in the Node-RED editor itself. The solution that I would like to achieve would be to have a configuration page on the Dashboard to input new IP address and configure each device from there, or to have it be automatic in the future.
I would like to know if there is any way to change the node Configuration other that in the Node-RED editor. I thought that this might be accomplished by using Admin HTTP-API, but is seems like there is no option like that. I also tried to use HTTP endpoints but with no success.

Did anyone found the solution for such problem, or maybe there is something that I could use to dynamically change the configuration nodes?

Not directly what you asked for, but did you try using a hostname or fully qualified domain name instead of an IP address?

What node or nodes are you using?

I mainly use those libraries:
and possibly more to come as time goes by. All of those node configs need to be modify with needed IP address.

The nodes I'm using (list above) need to have IP address specified in order to connect. The devices I'm connecting to don't have domain name.

Perhaps using environment variables would solve the problem. You could set them either in the OS or in settings.js. Then it would need a node-red restart to implement them,.

Maybe I'm not that good at this stuff, I'm struggling to set it up correctly and I need your help.
Do you refer to $env('ENV_VAR')

or similar? What is the way of providing this inside config node? Should I use




I have problems with both. I also tried functionGlobalContext from settings.js but again I don't know how to pass this variable information inside config node.
What would be the format of providing this variable inside config node?

Neither. See Using environment variables : Node-RED

So when configuring a node, if you have an environment variable MYVAR you would put

I'm not having fun time with environmental variables, I tried using that, but is seems a little too much hustle to get the job done. Also environmental variables are differently access or set on different operating systems. In my case it's not the good solution for this problem. Still looking forward for something that could actually work.
Maybe it's just me, but I'm wandering why Node-RED API doesn't support such changes in config nodes.

Did you think about giving names to the devices? Might be a much simpler solution than to fiddle with the IP addresses.

That was the first thing I thought about, but in this case it will not work, since I need to be connected to multiple devices that are same brand, same model, everything is the same, only IP is different. The devices are also sometimes completely erased, so the last thing I want is to constantly configure the names.
I think I will give a second try to environmental variables, since probably it's the only way out from this situation.

Just try to use Environment variables then.

Works for the sftp node (top node uses domain name, bottom node uses ${SERVER}.


[{"id":"b9c7403504af3227","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":920,"y":120,"wires":[["8b391595152c576b"]]},{"id":"8eb0fd6a7db18620","type":"debug","z":"f6f2187d.f17ca8","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1240,"y":120,"wires":[]},{"id":"3a5089d531e25ac2","type":"comment","z":"f6f2187d.f17ca8","name":"","info":"","x":980,"y":60,"wires":[]},{"id":"8b391595152c576b","type":"SFTP-main","z":"f6f2187d.f17ca8","path":"/","method":"list","remoteFilePath":"/","localFilePath":"/","remoteDestPath":"/","useCompression":"","encoding":"utf8","mode":"","recursive":"false","server":"40c9657850c479d8","x":1090,"y":120,"wires":[["8eb0fd6a7db18620"]]},{"id":"0c71767e8b0b37d7","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":920,"y":200,"wires":[["63c17f53549ba746"]]},{"id":"fb2a7a05a5030326","type":"debug","z":"f6f2187d.f17ca8","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1240,"y":200,"wires":[]},{"id":"63c17f53549ba746","type":"SFTP-main","z":"f6f2187d.f17ca8","path":"/","method":"list","remoteFilePath":"/","localFilePath":"/","remoteDestPath":"/","useCompression":"","encoding":"utf8","mode":"","recursive":"false","server":"40c9657850c479d8","x":1090,"y":200,"wires":[["fb2a7a05a5030326"]]},{"id":"40c9657850c479d8","type":"SFTP-credentials","host":"${SERVER}","port":"22","username":"demo","password":"password"}]

Defined in docker like this:

version: '3'

    image: nodered/node-red
      - TZ=Europe/Berlin
      - SERVER=
      - 1880
    restart: always
      - /data
1 Like

Thank you for all advices.
I wrote a simple power shell script that is setting all environmental variables from a configuration file and then starts node red. All config nodes that need 'special' configuration use ${ENV-NAME}. On the dashboard I made a configuration page that first reads the environmental variables for displaying, and the user can change them. The only thing that I didn't implemented yet is the automatic restart of the whole process. After saving the variables the user need to manually restart the power shell script to set up everything with new variables.
I guess there could be a way to write some sort of daemon script that will check if node red was stopped (preferably with some exit return code) to then restart all processes to set new env variables.
The other thing that I left for now is the password encryption. I would like to store the passwords encrypted and set them as environmental variables in some way, just to make it more secure.

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