It’s been a while since I last posted anything here. I have not been doing much regarding the topics of this blog lately, but now it seems a good time follow up with a little post on some maintenance.
I have been running Node-Red version 0.11.1 since 2013 when I initially started using it and have not had any particular reason to upgrade it, until recently.
Recent releases of Node-Red offers some quite welcome features, such as compatibility with newer versions of Node.js on the PI (but not 4.x, it seems) as well as an updated version of the graphical design framework used by Node-Red, which now offers snap-to-grid and better use of screen real estate. Further, many of the core nodes have better configuration options.
I faced several challenges during the update process, most of which were caused by my initial installation of both Node.js and Node-Red being clumsy. In fact, I had to completely remove both Node.js and Node-Red and install them anew!
To remove Node.js and Node-Red completely from the system I performed the following steps:
- Log in to Node-Red and export all flows
- Log in to the Raspberry PI in a Terminal and backup any custom settings that you might have made, e.g. to the
- Still logged in to the PI, write enable the drive:
- Remove the old Node-Red installation:
sudo npm -r -g node-red
- Clean the nam cache:
sudo npm cache clean
- Remove the old Node.js installation:
sudo apt-get remove nam nodejs
- Make sure to remove all remnants of npm, Node.js and Node-Red, except for the
~/.node-redfolder, which contains your flows. Especially the
node_modulesfolder(s) can cause trouble because any binaries left over might not be compatible with a newer version of Node-Red.
Now that the system is cleansed from Node.js and Node-Red it is ready for a fresh install. It is my experience that version 4.x of Node.js is not yet well supported on Raspberry PI, which is also evident from the fact that Heroku, at the time of writing, does not provide a Node.js 4.x download for Raspberry PI. Thus, I will describe how to update to Node.js version 0.12.x, which does have support for the newest version of Node-Red (13.3). Do this by following the steps below, while still being logged in to the Raspberry PI in a Terminal:
- Make sure that the package manager is up-to-date with the latest packages:
sudo apt-get update
- Install Node.js, e.g. by following my guide on installing Node-Red, which also explains how to install Node.js
- Update npm to the newest 2.x version:
sudo npm i -g --unsafe-perm -d email@example.com
- Install Node-Red, e.g. by following my guide on doing so. Also make sure to install any additional nodes that you might need – remember to always include the arguments
-gto npm to avoid permission issues and install nodes globally.
- Restore the configurations and settings that you backed up
- Start Node-Red:
sudo service nodered start– this only works if you initially installed the init.d script (again, see my guide on installing Node-Red) and did not remove it earlier.
- Log in to Node-Red and see if everything works
Challenges when upgrading Node-Red
When updating npm on Node.js version < 4 it is important, at least for my particular configuration, to stay on version 2.x. Initially, I updated npm to the newest version, but this caused me a bit of trouble when installing
node-red-node-serialport because it would then install a version that required a version of
node-serialport for which no binaries exist for the PI and which, in turn, would not compile properly. Supplying the version designation in step 3 above solves this problem as described on the site for
Challenges after upgrade
One of the challenges I faced after upgrading Node-Red from version 0.11.1 to 0.13.3 was that my flows did not show up correctly in the browser. They worked all right behind the scene, but the graphical representation in the browser was screwed up.
After a little investigation I could establish that a new property,
scope, had been introduced for the catch node. This property was not defined for the catch nodes in my old flow – a plausible cause for the error. After adding the
scope property to all catch nodes in my flows (by editing the flows file in
~/.node-red/) and restarting Node-Red I still got the same error.
Luckily, the catch node does not require much configuration and basically just flows to another node, so I took a backup of my flows file and edited it by removing all catch nodes, making sure that there were no references to them.
That worked and I could successfully load the flows in the browser and add the catch nodes again. I have not found any difference between the format and definition of the old catch node compared to the new ones I defined in the flow, so the difference may have been elsewhere, however I got it sorted out without much difficulty.
While I had some trouble updating Node.js and Node-Red in a more compelling way than doing a complete reinstall of the two components, this task was not as complicated as I had initially expected it to be.
Just remember to back up your flows before doing any changes to the installation!