Installing Node Red
Node-Red is a node application and before you Install node red you will need to first install node. Here are the instructions:
Then you can Install node red on Windows and Linux (including raspberry pi) using:
npm install -g --unsafe-perm node-red
Using the -g option adds the node-red command to your path. On linux you will need the sudo option. See the documentation.for more details.
Node-Red on Pi Notes:
Node red is already installed on Raspberry pi but npm (node package manager) isn’t.
You may need to upgrade node-red which you can do by doing an install using npm but you will need to install npm first. This you can do using:
sudo apt-get update sudo apt-get install npm
Note: npm install failed on my pi and I had to use this command first:
sudo apt-get install -y build-essential
You can check the versions of npm,node and node-red using:
npm -v node -v node-red --help
However Raspberry pi provide an install script which can be used for installing and upgrading node-red on the pi and I recommend using it. The procedure for download and using it are here.
I recommend you copy the command from the page and paste it into your command prompt.
Starting Node Red
To start node red on Windows go to a command prompt and type:
if you installed node-red using the -g option.
Note: you may need to change into the node directory.
If it fails you can use:
Firstly running node by typing node may not work as apparently node is a short cut to nodejs and the short cut may not be present.
In addition there appears to be a naming conflict with another package. see this explanation
The screen shot show how to create the symbolic link
Now that node is working you can run node-red.
Type node-red at the command prompt
. If that doesn’t work it’s probably because the link isn’t configured as shown above. You can try the alternative.
As shown below
At the top of the screen you can see the version of node and node-red that you are using and the location of the flows..
At the bottom of the screen it tells you the url to use to access the node-red web admin interface which you use to create your flows.
This console stays open and you will find it useful as when you start creating flows as you will see log information appearing there.
Starting Node-Red as a Service
On Raspberry pi you can also start node-red using:
which starts node-red as daemon.
to stop it use:
and to view the log files type
Starting Node-Red on Boot
If it isn’t already configured you can automatically start node-red on system start by using the command:
sudo systemctl enable nodered.service
and disable it using:
sudo systemctl disable nodered.service
When running on start up you can stop it using the node-red-stop command and restart using node-red-start command.
If you want to load node-red on startup with a different settings file than the settings.js you will need to edit the file /lib/systemd/system/nodered.service.
un-comment the line ExecStart if not already done and the Environment=”NODE_RED_OTPIONS=-v” line to something like:
Node-Red Start Process Overview
When node-red starts it first loads the settings file settings.js which is used to set the admin port, user directory, and flows file etc. The start process is illustrated below.
Node-red uses a settings file called settings.js.
On Linux it is located in the /usr/lib/node-modules/node-red/ folder by default. on Windows it is located in c:\node-install-directory\node-modules\node-red\ .
On Linux the settings.js file is copied from the /usr/lib/node-modules/node-red/ folder to your .node-red folder in your home directory when you start node-red, and there is no settings.js file present.
You can create your own settings file and customise it either by copying the existing file or using the file available from Github here.
To use your own settings file use the -s switch when starting node-red e.g.
node-red -s mysettingsfile.js
Important -If you place a settings.js in the .node-red folder then that will be used by default.
The documentation here takes your through the settings file in detail.
The .node-red Folder
On both Windows and Linux user settings and flows are stored in the .node-red folder. This folder is located in the users home folder.
E.G For user steve on windows and on Linux
/home/steve/.node-red ……….. Linux
Node-red Flows Files and Storage
Node red flows are stored in a .json file in the .node-red folder.
By default this file is called flows_machine_name.json. For example my windows machine is called ws6 and the default flows file is called flows_ws6.json.
New modules that you install are installed under the node_modules folder in the user directory which by default is .node-red.
Useful Command line Options
Node red has a very limited number of command line options. Use:
The -v switch turns on verbose mode.
The -p switch will let you change the port that node-red admin interface uses.
You can use this option to quickly and easily run multiple instances of node-red.
In version .20 a safe mode has been added to allow you to start node-red without deploying any flows.
This is very useful if a flow is stopping node-red from running.
To use a different flow file than the default you can use
Because you haven’t specified a settings file it uses the default settings file.
Running Multiple node-red instances
It is possible to run multiple node-red instances on a single machine.
To do that you will need to give each instance a different admin port and also a different user directory or alternatively create and use a new settings file.
You can do this using the -p and -u switches when starting node-red e.g
node-red -p 1881 -u user1
the admin port is 1881 and the user directory is user1 the flow file name uses the default flow name.
Note: If you don’t use a different user directory then they will all use the same flows file which could result in conflicts.
If you create a new settings file e,g mysettings.js you can then edit the line starting with flows and remove the two forward slashes.
// flowFile: my’flows.json’,
You could also change the port by editing the line near the top of the file
uiPort: process.env.PORT || 1880,
uiPort: process.env.PORT || 1888,
To use port 1888
You then use the command:
node-red -s mysettings.js
to start the flow.
You could also use the command
node-red -s mysettings.js -p 1889
to use a different port.
Video Node Red Flow and Startup Files
0 of 10 questions completed
Test your knowledge of Basic Node-red setup
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
0 of 10 questions answered correctly
Time has elapsed
You have reached 0 of 0 points, (0)
Question 1 of 10
Node-Red Runs is a XXXXX Application ?Correct
Question 2 of 10
The default port for administering node-red is?Correct
Question 3 of 10
The default settings file is called?Correct
Question 4 of 10
You start node-red from the command line but it fails to start with the Error Message
Error:Port in Use
What is the most likely cause?Correct
Question 5 of 10
Which of the following statements are true?Correct
Question 6 of 10
What does the following command do?
node-red -s mysettings.js -p 1889Correct
Question 7 of 10
You are using Node-red on a machine called raspberrypi. What is the name of the flow file created by default.Correct
Question 8 of 10
Besides the flow file node node also creates additional files in the .node-red folder. On a server called raspberrypi you would expect to see th following files:
Question 9 of 10
To create passwords for the admin interface you need to install the command line admin tools?
True or False?Correct
Question 10 of 10
The dashboard nodes are part of the core nodes and installed by default?
True or False?Correct
Related Tutorials and Resources: