Install Node.js on Raspberry Pi
With the Raspberry Pi properly set up, login in via SSH, and update your Raspberry Pi system packages to their latest versions.
Update your system package list:
Upgrade all your installed packages to their latest version:
Doing this regularly will keep your Raspberry Pi installation up to date.
To download and install newest version of Node.js, use the following command:
Now install it by running:
Check that the installation was successful, and the version number of Node.js with:
Get Started with Raspberry Pi and Node.js
Now you have a Raspberry Pi with Node.js installed!
Having an SSH connection established with your Raspberry Pi, enter the following commands to install Node-RED:
pi@raspberry:~ $ bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)
The installation should be completed after a couple of minutes.
Autostart Node-RED on boot
To automatically run Node-RED when the Pi boots up, you need to enter the following command:
pi@raspberry:~ $ sudo systemctl enable nodered.service
Now, restart your Pi so the autostart takes effect:
pi@raspberry:~ $ sudo reboot
Testing the Installation
When your Pi is back on, you can test the installation by entering the IP address of your Pi in a web browser followed by the 1880 port number:
In my case is:
A page like this loads:
Let’s take a look at the Node-RED visual interface.
On the left-side, you can see a list with a bunch of blocks. These blocks are called nodes and they are separated by their functionality. If you select a node, you can see how it works in the info tab.
In the center, you have the Flow and this is where you place the nodes.
Creating a simple flow
Let’s test a simple example of a flow. Start by dragging an Inject node to your flow. Then, also drag a Debug node.
Connect your nodes together. You can drag them to confirm that they are connected.
Now, let’s edit the inject node. Double-click the node. In the figure below you can see different settings you can change.
Select string and type Hello!.
To save your application, you need to click the deploy button on the top right corner.
Your application is saved.
Testing the flow
Let’s test our simple flow. Open the debug window and click the Inject node to trigger the “Hello!” string.
As you can see, our message is being printed in the debug window. This is a very basic example and it doesn’t do anything useful. However, the purpose of this post is to get you familiar with the Node-RED interface.
This post is a quick guide to setup Node-RED on a Raspberry Pi and create a simple flow. I’ll be posting future tutorials doing things with a real world application, but I thought it would be useful to introduce this software first.