Only just seen this but I think you are approaching it the wrong way.
As you've already seen, you quickly fall foul of OS differences if you aren't careful.
The node-red port is available from the node-red settings object so that is easy enough.
The IP address varies depending on whether you want the internal or external address.
In node.js, os.networkInterfaces()
will give you the data you want on any platform. All you need to do is grab the data in settings.js and assign to a global variable. No need to make it persistent and you shouldn't do anyway in case the address changes.
Oh, a complexity of course. I you are looking for the nr server address as seen by a client connection, that is actually harder if you need it to be a generic solution. That is because a particular node-red installation might be behind 1 or more proxies which would impact the address that the client would need to connect to.
Really depends on why you want to capture these details and where they will be used.
Not sure if this translates directly to a function node but here is the trace log message from uibulder that reports the node-red server details on startup:
log.trace(`[uibuilder:web:webSetup] Using Node-RED ExpressJS server at ${RED.settings.https ? 'https' : 'http'}://${RED.settings.uiHost}:${RED.settings.uiPort}${uib.nodeRoot === '' ? '/' : uib.nodeRoot}`)