Upgrade Node-Red 0.11.1 to 0.13.3

Upgrading Node.js and Node-Red on Raspberry PI running EmonBase

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:

  1. Log in to Node-Red and export all flows
  2. Log in to the Raspberry PI in a Terminal and backup any custom settings that you might have made, e.g. to the settings.js file
  3. Still logged in to the PI, write enable the drive: rpi-rw
  4. Remove the old Node-Red installation: sudo npm -r -g node-red
  5. Clean the nam cache: sudo npm cache clean
  6. Remove the old Node.js installation: sudo apt-get remove nam nodejs
  7. Make sure to remove all remnants of npm, Node.js and Node-Red, except for the ~/.node-red folder, which contains your flows. Especially the node_modules folder(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:

  1. Make sure that the package manager is up-to-date with the latest packages: sudo apt-get update
  2. Install Node.js, e.g. by following my guide on installing Node-Red, which also explains how to install Node.js
  3. Update npm to the newest 2.x version: sudo npm i -g --unsafe-perm -d npm@2.x
  4. 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 --unsafe-perm and -g to npm to avoid permission issues and install nodes globally.
  5. Restore the configurations and settings that you backed up
  6. 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.
  7. 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 node-red-node-serialport.

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.
A quick glance at the developer console in Chrome revealed a lot of JavaScript errors. The initial error was something about a label property that could not be read when parsing a catch node (the all too familiar cannot read property xyz of null).
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.

Conclusion

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!

Oddly though, I was unable to find any real information on the Internet about upgrading Node-Red nor the JavaScript errors I faced. Maybe I have been unfortunate to have a very unique flow setup (I sincerely doubt that!) or others have not tried to update their Node-Red installation on the PI yet (I doubt that too). Anyway, for anyone else facing similar problems, I hope my solution can be of help.

0 comments on “Upgrading Node.js and Node-Red on Raspberry PI running EmonBaseAdd yours →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: