If like me, upgrading Node-Red (in my case on Raspberry Pi) is often problematic – then it may well be worthwhile reading this update – at last solving a long-lasting issue including SQLITE and other installs which rely on NodeJS.
If you regularly upgrade a Node-Red installation which makes use of the Node-Red SQLITE node, perhaps you use the serial port and/or i2c you may have come across installation failures – if so, read on.
Over the years I have upgraded my Node-Red installation which currently statnds at NR 1.32 – using the script below – which you will find on the Node-Red website.
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
After a successful upgrade to Node-Red 1.2.5 (leaving the SQLITE node slightly behind as it can be painful to update when there are node-js upgrades involved), I was feeling quite perky when along came NR 1.3.2 – which completely trashed my setup.
These days whenever I upgrade Node-Red I use that script above ( a link to which is also included in my own “The Script”) and I subsequently (no reboot required) use the 4 lines below on my Raspberry Pi 4 installations which came to life years ago on RPI2 and Raspbian Stretch and which have been upgraded to Raspbian Buster (now called Raspberry Pi OS) and updated regularly (without starting from scratch or losing valuable data).
Once you have done the Node-RED upgrade as user PI…you can use these 4 lines (again as user PI)..
node-red-stop cd /home/pi/.node-red npm rebuild sqlite3 node-red-start
Be warned – the SQLITE rebuild will throw out MANY warnings… even back in November 2020 – the improved NR script and the 4 lines above DID solve the SQLITE upgrade problem – but you MUST be in the correct directory as indicated for the latter). Use the 4 lines above AFTER upgrading Node-Red and perferably before starting to run Node-Red.
I originally noted while upgrading other NR nodes – that when it came to the SQLITE update in the NR pallette manager, SQLITE failed. I stopped NR and ran the above – which usually worked but this has always been a CONSTANT pain as there is always the chance that this fix would not work. It does seem to work just fine now but ALWAYS make a backup before upgrading SQLITE in particular.
The above represents a TINY fraction of the warning messages you see during the SQLITE rebuild. They are mainly utterly pointless warnings but watch out for any ERRORS – they will be reasonably obvious.
That’s it, nothing else, just those 4 lines EXACTLY as above and despite all those warnings, the SQLITE upgrade worked just fine using NodeJS 10 – well, that is, this has worked well in the past but By April 2021, Node-Red was wanting to use NodeJS 12.x – and I found myself back at square one.
Update April 2021 – upgrading to NR 1.32. – I ran the NR upgrade script which Killed node.js v10 – installed node v12.22.1 and npn 6.14.12 – installed node-red 1.31 (previously was 1.2.9)… no other messages. Firstly I2c failed “Error: Could not locate the bindings file” – I was not actually using i2c in NR so I simply removed reference to it in the Node-red setting.js file – this time however that 4-line upgrade script failed – “This is NOT a problem with NPN” it said… so I tried rebooting and ran the SQLITE3 4-liner again – STILL no SQLITE…. so I tried something from a long time ago – deleting /home/pi/.node-red/node_modules/node-red-node-sqlite and re-ran the 4-line script – no further forward.
Node-Red said “node-red-node-sqlite (0.6.0): sqlitedb, sqlite”
Thanks to help from the NR forums – I went back to my clone of an earlier NR – but this time, before running the official NR/Node upgrade script – I performed:
sudo-apt update sudo apt full-upgrade
The “full-upgrade” is important. THIS time after rebooting, I used the official Node-Red upgrade script as above – and everything WORKED without any messing with SQLITE, no i2c or serial issues. I can confirm the upgrade to NR 1.3.2 worked – and I’ve since upgraded all nodes that needed upgrading – without ANY issues – but for one tiny thing – this time, the NR upgrade script did NOT try to upgrade Node.JS which remained at 10.23.3 – since then I’ve spoken to the guys on the Node-Red forum (Colin and Dave in particular) and FINALLY – I’m BANG up to date with Node-Red AND Node-JS… if only I’d had this knowledge in the past… see this discussion… which includes (vitally) changing a file on the RPi which tells it which version of NodeJS it should be upgrading to…
It turns out as you’ll see in the link above, that everytime I thought I was upgrading modules to the latest NodeJS, I was wrong as I’d missed out one vital step, telling my RPi which version of NodeJS to use.
it is important to ensure you do not have multiple installs of SQLITE – I had a GLOBAL install, another in the /home/pi/node_modules folder and finally an install in /home/pi/.node-red/node_modules – and my problems were largely as a result of no binaries being available for SQLITE (this also affects some other nodes) which means the installation needs ro “rebuild” them automatically from source to work with the updates NODEJS – and that means your system needs to be aware of which NodeJS it should be using – that does not happen automatically. See details in the discussion above.
It turns out that my global (-g) SQLITE installation was a legacy from years back and the /home/pi/node_modules folder IN TOTAL was a duplicate – after cloning my installation I removed that folder altogether. Indeed for a typical Node-Red installation, it seems (as you will see in the discussion above), Node-Red itself is globally installed – everything else should be installed from the /home/pi/.node-red folder (i.e. locally). As a result of this it looks like the NR developers may now skip NodeJs 12 and recommend NodeJS 14 – and that’s where I stand mid-April 2021 – NR 1.3.2, NodeJS v14.16.1 – i.e. fully up to date WITHOUT losing my data or starting from scratch – despite what you may read elsewhere, it IS possible to take NR installations from as far back as Raspbian “Jesse” or “Stretch” all the way through “Buster” to the latest Raspbian named simply “Raspbian OS” while retaining whatever content you may have built up over time.