Where can I access RED.settings?

In this thread, @Steve-Mcl says "You do not have access to RED.settings in a function node." Perhaps this is a stupid question, but where in a flow do I have access to it? It's not in any of the dropdowns (e.g. in the CHANGE node) to allow me to access it there, so where else in a flow can I use JavaScript directly so that I can access it? Or is it perhaps only available in node definitions?

A flow has no access to RED.settings

None of the core nodes expose it in anyway and we'd strongly council against any contrib node giving access.

Oh. Even careful, selective, read-only access? I just want an easy way of finding out [in a flow] the host and port on which Node-RED is running without having to configure it anywhere. (It seems the icon URL passed to worldmap needs to be a full URL, not just a path.) So if I start Node-RED using node-red -p 1881 I want to be able to retrieve 1881 from somewhere. Perhaps I'm going about this the wrong way?

Read-only access from a custom node is OK. But access from a flow is not so good because it collapses the separation of concerns. The settings.js may contain information that users should not have access to even to read. Use with caution.

The best way to safely share such things with flows is to add them as global variables in settings.js itself. Just make sure that whatever you share, you don't mind sharing with anyone who has access to the Editor.

Thanks. It's a shame I have to provide a full icon URL to the worldmap, really, as that's where this all started! I've just implemented an even worse approach than creating a custom node, if you can believe that (don't ask) but I dislike it so much I think I'll undo it and find something more dependable.

I appreciate the thoughts, @TotallyInformation and @knolleary.

Adding the setting to your globals is easy enough and is fine if that is the need. It is a common enough need to provide access to things like the Node-RED port number. Of course, there is an alternative that is much better for end users and that is to use a reverse proxy to hide the port number and ip address completely. Use an ip name with the default ports (443 for https hopefully) and shift things onto paths as needed. Not terribly hard to do and will even still run on a Pi as long as you don't go mad with the flows and number of users. There are plenty of examples shared in the forum.

In case anyone else wants to use Node-RED to serve up icons used in worldmap, my pull request to Let icon "url" be a local fixed path was included in v2.34.0.

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