I'm experiencing a strange issue where Node-RED starts on a random port (e.g., 20901) even though my settings.js file explicitly sets uiPort to 1880. I'm running Node-RED v4.0.9 on Windows Server 2019 within a VMware virtual machine. I've already checked for port conflicts, environment variables, and any command-line arguments that might override the port setting, but haven't found any obvious causes. I've also tried reinstalling Node-RED and cleaning the npm cache, but the issue persists.
Here's what I've checked so far:
No other processes are using port 1880 (checked with netstat -aon).
The PORT environment variable is not set.
I'm not using any command-line arguments to specify the port.
My settings.js file is correctly loaded by Node-RED (confirmed in the log).
There are no errors in the Node-RED log related to port binding.
I've tried temporarily disabling the dashboard nodes, but that didn't make a difference.
I've confirmed that port 1880 is open in the Windows Firewall.
I'm wondering if there might be something specific to VMware's network configuration that's causing this issue. I've checked the VM's network settings, and it's currently using NAT. I haven't configured any port forwarding rules in VMware.
Has anyone else encountered this issue with Node-RED in a VMware VM, or have any suggestions for further troubleshooting? Any help would be greatly appreciated!
Welcome to Node-RED
===================
25 Feb 16:24:55 - [info] Node-RED version: v4.0.9
25 Feb 16:24:55 - [info] Node.js version: v22.14.0
25 Feb 16:24:55 - [info] Windows_NT 10.0.17763 x64 LE
25 Feb 16:24:56 - [info] Loading palette nodes
25 Feb 16:24:59 - [info] Settings file : C:\Users\yhernandezperez\.node-red\settings.js
25 Feb 16:24:59 - [info] Context store : 'default' [module=memory]
25 Feb 16:24:59 - [info] User directory : \Users\yhernandezperez\.node-red
25 Feb 16:24:59 - [warn] Projects disabled : editorTheme.projects.enabled=false
25 Feb 16:24:59 - [info] Flows file : \Users\yhernandezperez\.node-red\flows.json
25 Feb 16:24:59 - [info] Server now running at http://127.0.0.1:20874/
25 Feb 16:24:59 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
25 Feb 16:24:59 - [info] Starting flows
25 Feb 16:24:59 - [info] [ui-base:Power Monitoring] Node-RED Dashboard 2.0 (v1.22.1) started at /dashboard
25 Feb 16:24:59 - [info] [ui-base:Power Monitoring] Created socket.io server bound to Node-RED port at path /dashboard/socket.io
25 Feb 16:25:00 - [info] Started flows
If it's not something in the settings.js then the only other place that would be in RED,js as the port is read from the settings.js and passed straight to the express instance.
I also run it using: node-red -p 1880, but same behavior, this a totally new installation, and I've spent the whole day after installing three other that works good, the only difference is that this time is a VM
Update: I've now completely uninstalled Node-RED and installed a fresh copy without importing any flows, but I'm still experiencing the same issue with the port being randomly assigned. This leads me to believe it might be related to my virtualization environment (VMware Workstation). I'm not sure what specific settings or configurations within VMware could be causing this, especially since the virtualization environment is managed by our IT department, and I don't have direct control over it.
If anyone has any experience with running Node-RED in a corporate VMware environment and has encountered similar port issues, I would greatly appreciate any insights or suggestions. It might be helpful to know what specific questions or requests I should make to our IT team to help resolve this.
Can one add logging at the end of settings.js, I have not been able to work out how. It does not complain about using console.log but it does not appear to do anything.
Quite some time ago, I made a small change to my settings files. The node-red master version directly exports the object and so limits what you can do. I changed it so that the object is assigned to a constant first and then the constant is exported. This allows you also to manipulate the object before exporting - so that you could, for example, set one property based on another which you cannot do if you direct export.
// ...
const nrsettings = {
// ...
} // ---- End of exports ---- //
/** Splitting the export this way allows us to dynamically override settings if we want to */
nrsettings.functionGlobalContext._port = nrsettings.uiPort
module.exports = nrsettings
So you can do anything you want as long as it is before the module.exports line.