So what happens when your httpsRefreshInterval timer is executed:
Line 235: The contents of your privkey.pem file are read (via your readFileSync command), to get your private key.
Line 235: Also the contents of your fullchain.pem file are read (via your readFileSync command), to get your corresponding certificate.
We only arrive at line 238 if both file exists and have been read.
Line 238: it is checked whether you have already a server.key. Which means Node-RED checks whether the NodeJs http(s) server has already a private key. If there was previously no key used in your NodeJs http(s) server, then the key from your privekey.pem file should be used anyway.
Line 238: it is also checked whether your current private key (refreshedHttps.key) is equal to the server.key. Which means Node-RED checks whether the key that the NodeJs http(s) server currently uses is equal to the key from your privkey.pem file. Because we only update the private key in the NodeJs http(s) server when that key has changed.
In your case step 5 fails. Which means the server.key is not undefined, but I assume it is not a string (like we expected).
My first thought was that perhaps in a recent NodeJs version, the server.key mechanism has changed an it now returns a function or a promise or ... But when I look at the NodeJs code, I don't immediately see something different (like a wrapper function or something like that)
Can you give some more information:
Your NodeJs version (from your Node-RED startup log)
I 'think' it is becoming clear to me know why it fails in your case.
When I implemented this feature (see pull request), I checked whether the private key was updated in this way:
if ( ... !server.key.equals(refreshedHttps.key) ... )
In Java that would have been fine, but seems now not in Javascript...
Whether the server.key has an 'equal' function, depends on how you read your key file:
key: require("fs").readFileSync('...') returns a raw buffer, since you have not specified an encoding (see here). And a NodeJs buffer contains an equals function (see here).
key: require("fs").readFileSync('...', 'utf8') returns a string, and in Javascript a string has no 'equals' function
Seems my old Java background has caused this issue ...
@knolleary : I assume it is best if we fix this, because keys/certificates in string format should also work correctly... But not sure if you have a preferred way to check the equality of two items? Simply by coding, or by using an npm module, or ...