Re: Identifying running port of Node Red

Continuing the discussion from Port number of running node-red instance:

@knolleary you mentioned that the admin port was available using
RED.settings.port

Following on from the suggested solution in the linked post, in a function node if I type msg.payload = RED.settings.uiPort;
the response is that settings is undefined.

Hence my original question, is this no longer a valid solution?
Is RED.settings.uiPort available in function node or only in a custom node?

In our version (3.0.2) I exported 'RED' to message.payload in order to see what was there (passed it to a debug node).
i.e. msg.payload = RED;
I don't know if this is a valid approach but it returned the following:
util>
encodeObject: function
ensureString: function
ensureBuffer: function
cloneMessage: function
compareObjects: function
generateId: function
getMessageProperty: function
setMessageProperty: function
getObjectProperty: function
setObjectProperty: function
evaluateNodeProperty: function
normalisePropertyExpression: function
normaliseNodeTypeName: function
prepareJSONataExpression: function
evaluateJSONataExpression: function
parseContextStore: function
getSetting: function

For context we have a subflow who's job is to restart all flows in the case of a catastrophic failure. Originally we had the port hard coded. Found the linked thread (above) to determine the admin port.

We will likely go down the path of adding the port as a variable to global (the other solutions documented in the original thread), this will of course preclude the use of -p in the command line but I think we can live with that.

Appreciate any advice.
Rob

What I do is change round the settings.js slightly so that the settings object is assigned to a variable and separately applied. That way, the settings can be assigned to a global.

const nrsettings = {
   // ...
}

/** Splitting the export this way allows us to dynamically override settings if we want to */
nrsettings.functionGlobalContext._port = nrsettings.uiPort

module.exports = nrsettings

Then it is available as a global context variable.

That looks like a good solution - will give it a try.

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