Raspberry Pi 2 Node-Red setup

In order to setup node-red, node.js is required.  Node.js runs on javascript and is one of the building blocks of node-red.  The install processes for Raspberry Pi and Raspberry Pi 2 are different and have different instructions.  Below are instructions for Raspberry Pi 2 and I have tested this process on Raspian wheezy 2015-20-16.  These are my own notes for my own purposes, but hopefully somebody else will find them useful too.

Before running these, update Raspian first.

sudo apt-get update
sudo apt-get upgrade


To install node-red for the Raspberry Pi 2, the node-red guys have made it much easier.

Run the following command. This will update the raspian package cache and the source list.

curl -sL https://deb.nodesource.com/setup | sudo bash -

Now to install all the packages.

sudo apt-get install git-core screen build-essential python-dev python-rpi.gpio nodejs

Verify that node and npm have installed correctly. Run the following.

node -v
npm -v

You should get results similar to the following.

pi@pi2 ~ $ node -v
pi@pi2 ~ $
pi@pi2 ~ $ npm -v
pi@pi2 ~ $

Once these are installed, run the following command to install node-red.

sudo npm install -g --unsafe-perm node-red

This takes quite some time.

I got a few warnings and the build of the node-icu-charset-detector node failed completely, however node-red still built successfully.

Now to test node-red. Run the following to start node-red from the command line.

node-red-pi --max-old-space-size=64 -v

Node-Red should start and should look something like this.

pi@pi2 ~ $ node-red-pi --max-old-space-size=64 -v

Welcome to Node-RED

16 Apr 20:12:47 - [info] Node-RED version: v0.10.6
16 Apr 20:12:47 - [info] Node.js  version: v0.10.38
16 Apr 20:12:47 - [info] Loading palette nodes
16 Apr 20:12:52 - [warn] ------------------------------------------
16 Apr 20:12:52 - [warn] [arduino] Error: Cannot find module 'arduino-firmata'
16 Apr 20:12:52 - [warn] [redisout] Error: Cannot find module 'redis'
16 Apr 20:12:52 - [warn] [mongodb] Error: Cannot find module 'mongodb'
16 Apr 20:12:52 - [warn] ------------------------------------------
16 Apr 20:12:52 - [info] User Directory : /home/pi/.node-red
16 Apr 20:12:52 - [info] Flows file     : /home/pi/.node-red/flows_pi2.json
16 Apr 20:12:52 - [info] Server now running at
16 Apr 20:12:52 - [info] Starting flows
16 Apr 20:12:52 - [info] Started flows

You should get the node-red web interface by going to the following page in your web browser.

http://<Pi 2 IP Address>:1880

Now to install an initialisation script so that node-red can run as a service and start/stop automatically on startup/shutdown.  Create a new init.d file by running the following.

sudo nano /etc/init.d/node_red

Then copy and paste the script below into this file and save.  This script will run node-red as the user pi.  It’s very simliiar to the Adafruit (link below) except updated for the new installs for Raspberry Pi 2.

#! /bin/sh
# Starts and stops Node-RED
# /etc/init.d/node_red
# Provides:     node_red
# Required-Start:       $syslog
# Required-Stop:        $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Node-RED initialisation
# Note: this runs as the user called pi


#Load up node red when called
case "$1" in

        echo "Starting Node-Red.."
        su -l pi -c "screen -dmS red node-red-pi --max-old-space-size=64 -v"
        echo `screen -ls red | sed -n '2p' | cut -f1 -d.` > $PIDFILE

        echo "Stopping Node-Red.."
        su -l pi -c "screen -S red -X quit"

        echo "Restarting Node-Red.."
        $0 stop
        $0 start
        echo "Usage: $0 {start|stop|restart}"
        exit 1

Once the init script has been saved, it needs to be made executable and added to rc.d so it will start and stop at startup and shutdown.

sudo chmod +x /etc/init.d/node_red
sudo update-rc.d node_red defaults

You can also start/stop/restart the node-red service using this script.

sudo service node_red start
sudo service node_red stop
sudo service node_red restart

node-red addons

There are many addons for node-red.  Some of my favorites are ping, wol, emoncms, prowl, mysql and pushbullet – but there is many others. To install them, use npm from the node-red directory.  The following will install my favorite addons.

sudo service node_red stop
cd /usr/lib/node_modules/node-red
sudo npm install node-red-node-pushbullet
sudo npm install node-red-node-wol
sudo npm install node-red-node-ping
sudo npm install node-red-node-prowl
sudo npm install node-red-node-emoncms
sudo npm install node-red-node-mysql
sudo service node_red start

There are many other addons and you can find other packages at https://www.npmjs.com/


I found that the install didn’t always successfully compile all addons. If there is an addon you expect to see in the node-red GUI that is not there, you can enable more verbose logging.  It should tell you if it is getting any errors or if it cannot load a specific module.  The below will run node-red manually from the command line.  Ctrl-C to break out.

sudo service node_red stop
node-red-pi --max-old-space-size=64 -v

Useful node-red sites & references

Adafruit has a very nice guide for setting up node-red on a Raspberry Pi (version1). Very useful.

Has many npm packages which can be installed.

The Node-Red site.

Interesting demo. Twitter, Mongo REST API and sentiment Analytics in 3 minute demo.

The Git Hub repository for Node-Red.


5 thoughts on “Raspberry Pi 2 Node-Red setup

  1. Karl September 22, 2015 / 9:34 AM

    Splendid information. I wish I would have found your website two days ago, LOL. Perfect information for RPI 2.

    Thanks again,



  2. Tom Sepe December 7, 2015 / 7:53 PM

    HI I’d just like to point out that you script requires use of the package “screen” which is not included in the latest Raspbian Jessie build as of 12/5/15. Once I did “sudo apt-get install screen” the script worked fine.


    • swab13 December 7, 2015 / 9:36 PM

      Thanks Tom, good point. I used screen due to ease I could resume the node-red screen for troubleshooting.


  3. Jeet Prashantsagar Parikh January 16, 2017 / 4:32 PM

    i’m following the same way as they given ut it’s not working after the verify potion. error look like after npm -v or node -v is

    -bash: node: command not found


    • Steve WB January 17, 2017 / 10:52 PM

      Did the previous sudo apt-get install successfully complete?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s