#Installing Node-RED on the RoadRunner

<abstract>
Node-RED is a programming tool for wiring together hardware devices, APIs and online 
services in new and interesting ways.
It provides a browser-based editor that makes it easy to wire together flows 
using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.
This article explain how to instal and use it the Roadrunner board
</abstract>

##Installation

To install [Node-RED](http://nodered.org/) on the Roadrunner board type these command at Linux prompt to
install first [Node.js](https://nodejs.org/en/):

	curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
	sudo apt-get install -y nodejs
	
and then the latest version of Node-RED:	
	
	sudo npm install -g --unsafe-perm node-red

When finished type:

	node-red 
	
to launch it open your browser at this page:	

* [http://roadrunner_ip_address:1880/#](http://roadrunner.local:1880/#)

All the working file related to this instance of Node-RED will be save inside
the directory <code>.node-red</code>. 

The file <code>~/.node-red/settings.js</code> can be changed to change for example the port used by Node-RED
or to protect the access on it via web.

## Launch automatically Node-RED at startup using Systemd

If your user name is for example <code>acme</code> create file like this:

	[Unit]
	Description=Node-RED 
	After=syslog.target network.target

	[Service]
	ExecStart=/usr/bin/node-red 
	WorkingDirectory=/acme
	User=acme
	Group=acme
	Nice=10
	SyslogIdentifier=Node-RED
	StandardOutput=syslog
	Restart=on-failure
	# Node-RED need a SIGINT to be notified to stop
	KillSignal=SIGINT

	[Install]
	WantedBy=multi-user.target

then save it in <code>/lib/systemd/system/node-red.service</code> and
type these commands:

	sudo systemctl daemon-reload
	sudo systemctl enable node-red
	sudo systemctl start node-red

It is possible to check any errors by checking the log file:

	sudo journalctl -f -u node-red -o cat

## Protect the access at Node-RED page

Install __node-red-admin__ by typing:

	sudo npm install -g node-red-admin

Create a password hash:

	node-red-admin hash-pw
	
add these lines in __.node-red/settings.js__ inside the __module.exports__ session:

	module.exports = {
		adminAuth: {
		    type: "credentials",
		    users: [{
		        username: "admin",
		        password: "put the password hash here",
		        permissions: "*"
		    }]
		},

Restart NodeRED:

	sudo systemctl restart node-red.service

## Enable the github content manager

Install __git__ by typing:

	sudo apt-get update
	sudo apt-get install git

launch nano to edit the file __setting.js__:

	sudo nano .node-red/settings.js

change this section:

	    editorTheme: {
	       projects: {
	           enabled: false
	       }
	    },

in:

	    editorTheme: {
	       projects: {
	           enabled: true
	       }
	    },

Restart NodeRED:

	sudo systemctl restart node-red.service
	
Check for any errors at NodeRED startup:

	sudo journalctl -f -u node-red -o cat

##Links

* @article='node-red-contrib-roadrunner'
* [Node-RED home page](http://nodered.org/)
* [Creating Nodes](https://nodered.org/docs/creating-nodes/)
* [Node-RED Library](https://flows.nodered.org/)
* <https://nodered.org/docs/getting-started/installation>
* <https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions>
* <https://nodered.org/docs/user-guide/projects/>
* <https://nodered.org/docs/security>
* <https://nodered.org/docs/node-red-admin>


@include='bio_tanzilli' 

