Tuesday, January 3, 2017

Upgrading Node.js and Npm on Raspberry Pi

Happy New Year!

This holiday I bought myself a Raspberry Pi (with a camera module) as I wanted to play with Node-RED on a real Internet-Of-Things device (the pi has Raspbian Jesse).

The default version of NodeJs on NOOBs is 0.12.x and some of the flows nodes do not work on this (e.g. node-red-contrib-python-function) since they might use ECMA6 syntax (e.g. lambda expression).
So, I had to upgrade the Node.js version to a newer version like 6.x.

After remo nodered, nodejs and npm I installed them back with the correct version (using sudo apt-get install nodejs npm nodered). Unfortunately, installing them this way do not install the node-red-start/stop commands. After a quick search online I found these commands:

sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.service -O /lib/systemd/system/nodered.service
sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start -O /usr/bin/node-red-start
sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop -O /usr/bin/node-red-stop
sudo chmod +x /usr/bin/node-red-st*
sudo systemctl daemon-reload

sudo systemctl enable nodered.service

These commands will install the node-red-start/stop commands and make it start when the device boots!

Pretty nice!

Happy coding!

No comments: