# Re: Identifying running port of Node Red

**URL:** <https://discourse.nodered.org/t/re-identifying-running-port-of-node-red/78979>\
**Category:** General\
**Tags:** function-node\
**Created:** [6 June 2023 01:34 UTC](https://discourse.nodered.org/t/re-identifying-running-port-of-node-red/78979 "2023-06-06T01:34:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobC](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@RobC](https://discourse.nodered.org/u/RobC)\
**Post date:** [6 June 2023 01:34 UTC](https://discourse.nodered.org/t/re-identifying-running-port-of-node-red/78979/1 "2023-06-06T01:34:52Z")

</div>

Continuing the discussion from [Port number of running node-red instance](https://discourse.nodered.org/t/port-number-of-running-node-red-instance/20166/12):

@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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [6 June 2023 08:23 UTC](https://discourse.nodered.org/t/re-identifying-running-port-of-node-red/78979/2 "2023-06-06T08:23:50Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![RobC](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@RobC](https://discourse.nodered.org/u/RobC)\
**Post date:** [7 June 2023 07:37 UTC](https://discourse.nodered.org/t/re-identifying-running-port-of-node-red/78979/3 "2023-06-07T07:37:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 August 2023 07:38 UTC](https://discourse.nodered.org/t/re-identifying-running-port-of-node-red/78979/4 "2023-08-06T07:38:08Z")

</div>

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