Say the value should be.... 20000
All things being good, the code loads and all is good with the world.
And I sorry now if I digress.
If it isn't set, I am wanting to have a default value that will get me there but also subtly indicate to me that the REAL value isn't set.
(This is kind of irrelevant but to put the cards on the table.)
Oh, and the SCAN_TIME can be altered via other systems.
So there is no FIXED value.
So if t isn't set, I make the value.... 15000
I don't know how the line would work:
cost scantime - global.get("SCAN_TIME") || 1500
if global.get("SCAN_TIME") is set to 20000 (or some other value.)
Again: Sorry. Does that make it clearer or just more confusing?
Ooooh!
Just tried what you said and it seems to work.
In an example function node.
I know you can't look in side my mind (the thought of that)
But I seem to be confused with what the || does with things.
|| is the logical OR operator.
The if statement is evaluated left to right.
Does nation equal "England"? No it doesn't, so on to the next test.
Does nation equal "Scotland"? Yes it does. At least one test has succeeded.
So the if test returns truewithout ever having to test "Wales"
In the global.get statement you imagine there are brackets around the right hand side let scantime = (global.get("SCAN_TIME") || 100)
It means "Evaluate the code in brackets and use the result to set scantime"
And in brackets we have "Get the value of the global variable OR (if that fails) 100"
By the way, when using || to get a default value, it is almost always safer to use ?? Best to get into the habit now that everyone should be on node.js v18 or above.
Because if there is ever any possibility that the left-hand-side of the ||might be either zero or Boolean false, it will not work as you expect. So you are in danger of getting a very hard to track-down bug.
The horridly named nullish coalescing operator ?? on the other hand only checks for null and undefined values, not for falsy values.
Hope that helps?
|| was designed as a Boolean OR operator and only later discovered to be quite handy for picking up default values.
If you are using a Linux server based on Debian or a derivative, you can use Dave's update script.
Otherwise, depends on your platform. For Windows, the easiest is simply to re-install Node.js with the newer version unless you are using winget or similar.
For Linux, I prefer to use the semi-official install repo's.
Looks like Node.js have upped their game recently. They have a nice new page:
Remember to choose an LTS version though. The latest version isn't always the best.
Hmm, they seem to be recommending fnm which is a node.js version manager. Most of us don't like those since they cause confusion about installed packages typically. I'd stick with the installer for windows or a native package manager for Linux (there is a small link at the bottom of the page that takes you to those).
I was sure I had this stuff written down somewhere.
The only update script I can find is this one:
## Version 2:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
# To also update node to the value given at the end.
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --node16