- Installing and Running Node-RED on a Windows PC
- 1. Introduction
- 2. Software & Equipment Requirements
- 3. Installing Node-RED
- 3.1 Node.js
- 3.2 Install Node-RED
- 4. Additional packages you will need
- 4.1 Node-RED-dashboard
- 4.2 node-red-contrib-modbus
- 5 Running Node-RED
- 6. An Overview of Node-RED
- 6.1. Palette
- 6.2. Workspace
- 6.3. Sidebar
- 6.4. Header
- Installing Node-RED as a Windows Service
- Installing Node-RED
- Securing Node-RED
- The Node-RED Service
- Troubleshooting
- Conclusion
- Richard Niemand
- Share this post
- Changing Sonoff Firmware (Visual Guide)
- Running Mosquitto as a Windows Service
- Running on Windows
- Quick Start
- 1. Install Node.js
- 2. Install Node-RED
- 3. Run Node-RED
- Alternative Installations on Windows
- npm on Windows
- Sharing Node-RED between Users
- Installing Node.js Windows Build Tools
- Running on Windows
- Using PM2
- Run Node-RED on Startup
Installing and Running Node-RED on a Windows PC
1. Introduction
Node-RED is a visual programming tool aimed at connecting hardware devices, APIs and online services in alternative ways, without the need for traditional programming experience. The software 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 run-time in a single-click. Although the concept of flows, nodes & palettes may sound unfamiliar, Node-RED makes programming simple by using a visual representation of code in blocks with lines between them.
Some examples of the many functions available are:
- REST clients to query data on other servers
- Modbus TCP client to talk to Brainboxes Remote IO devices
- JavaScript functions can be created within the rich text editor
- A built-in library allows you to save useful functions, templates or flows for re-use
- The flows created in Node-RED are stored using JSON which can be easily imported and exported for sharing with others
- An online flow library allows you to share your best flows with the world.
2. Software & Equipment Requirements
- A Brainboxes supplied Ethernet I/O device
- Any Windows PC/laptop
- Network connection
3. Installing Node-RED
The following are instructions on how to install Node-RED on a Windows based operating system. All required download links can be found on the official Node-RED and NodeJS websites.
3.1 Node.js
Node-RED uses a runtime engine called Node.js. Node.js is a JavaScript based programming language and must be installed before Node-RED. Node.js can be downloaded from the official Node.js website. When installing Node.js for use with Node-RED it is recommended that you install the 10.XX.X. LTS variant.
Once the installation is complete, open up a Windows command prompt, you can open a command prompt by using the keyboard shortcut (Windows key + r) type cmd and then once the command prompt has opened, input the following:
This command checks if both Node.js and NPM are correctly installed, and if so it will return a version number. The output should look something like this:
NPM is a package manager for the JavaScript programming language, this is needed for installing additional Node-RED packages which we will need later. NPM should be installed by default when installing Node.js.
3.2 Install Node-RED
Now we can begin to install Node-RED, navigate to CMD and input the command:
Please note if the module does not install and throws up error messages regarding permissions, you will need to run CMD in Administrator mode. If you are having trouble with this please contact your System Administrator. Once this command is ran Node-RED will begin to install. Please note this can take some time to complete.
Once complete, the output should look like this:
4. Additional packages you will need
There are some additional packages you will need to install when following this guide.
4.1 Node-RED-dashboard
The first package you will need to install is the Node-RED dashboard, this module adds nodes which allow us to easily create a live data dashboard.
To install this module simply open up a command prompt and input:
Please allow a few minutes for this to package install.
Please note if the module does not install and throws up error messages regarding permissions, you will need to run CMD in Administrator mode. If you are having trouble with this please contact your System Administrator.
When the module is successfully installed the response should look something like this:
4.2 node-red-contrib-modbus
The next package you will need to install is contrib-modbus, this module adds nodes that allow us to communicate in ModbusTCP
To install this module simply open up a command prompt and input:
Again, please allow a few minutes for this to install.
Please remember you may need to run this command on an elevated command prompt.
When the module is successfully installed the response should look something like this:
5 Running Node-RED
Once everything has been successfully installed you can now begin to run your Node-RED webserver. You can do this by navigating to a command prompt and typing in the following command:
As we installed Node-RED as a global NPM module it adds the command node-red to your system path which you can then input into a command prompt to start Node-RED
Once the server has booted up successfully the command prompt will let us know that the server is now running, and what IP address it is on.
Take note of the Node-RED webserver’s IP address and input it into your web browser
You have now successfully installed, booted up, and accessed your Node-RED webserver. You can now begin to create your own flows.
6. An Overview of Node-RED
So how do we get started? Below is an overview of the Node-RED interface, with a brief description of each section.
6.1. Palette
The palette on the left contains all the different nodes available for use. From injecting different types of information (strings, Booleans, numbers, etc.), executing Linux command lines and the ability to make different types of connections, to recording simple debug traces, sending emails notifications and displaying information on a text box.
6.2. Workspace
The workspace in the middle is where your flows will be created. As you follow through this simple guide, you will learn how the flows connect and work together in an easy to use, programmable way.
6.3. Sidebar
The sidebar on the right provides additional settings and debug information. Using the debug node available from the palette will show the user what information is being sent, or the information which is being received from the node it is attached to.
6.4. Header
The header at the top, contains the deploy button, which is used for deploying your current workspace. Deploying it will make it available for execution, or it will immediately start running, depending on how you have it set up. You will also find the main menu which allows you to import/export workspaces, or change several configurations regarding your Node-RED project.
Installing Node-RED as a Windows Service
In this post I am going to cover installing, configuring and running Node-RED as a Windows service. Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways, and is especially useful for home automation through IoT. There is a lot to cover, so let’s dive right in.
Installing Node-RED
Installation is pretty straight forward and requires only 2 simple steps, more detailed installation notes are available on the official Node-RED site should you need them.
The first thing you will need is any stable version of node.js installed. At the time of writing this article v6.10.3 was the latest stable build.
Once node.js is installed, open a command window and enter in the following command to install Node-RED.
That’s it Node-RED is installed and ready to be used, to launch it run » node-red » from the same command line.
Securing Node-RED
It is a good idea to secure your Node-RED installation with an username and password, especially if you would like it to be public facing. To secure Node-RED you will need to modify your settings.js file which is located in your users directory, in my case this is:
Locate the adminAuth section in the file and uncomment it. You will notice that there is a password property with a hashed password value assigned to it, we are going to need to generate a new hash for your password to replace it with. The Node-RED creators provide a tool for doing just this, and can be installed and run using the following console commands:
You will be prompted for your password 2 times and after the second time the node-red-admin tool will print out a hash value. The outputted value needs to find it’s way back into your settings.js file.
You will also need to modify the userDir property and hard-code it’s value to your .node-red folder. You need to specify the full path to the directory because when running Node-RED as a service the working directory may differ breaking any relative paths you may have defined. In my case I set userDir to the following:
Save and close the settings file.
The Node-RED Service
You will need to download a tool called NSSM in order to run Node-RED as a service — I covered NSSM in more detail in this post, however for now, all you need to do is download the latest version ( nssm 2.24-101-g897c7ad ) and copy either the 32-bit or 64-bit executable to any folder on your computer.
In a command line, navigate to the folder containing nssm.exe and run the following command:
This will present you with a dialog box similar to the one below.
On the Application tab enter in the below values, making sure that you adjust the paths where necessary.
On the Details tab, give the service a name and set it’s startup type to Automatic (Delayed Start) — this will ensure that Node-RED starts with Windows, but only once your computer has had some time to settle.
You now have a Node-RED service — under service manager, click the Start Service button to start your Node-RED service.
Troubleshooting
Should you run into any problems starting your new Node-RED service (like stopping immediately after starting it) you can follow the below steps to make identifying the issue a lot easier.
Navigate to the folder where you places the nssm.exe executable and run the following command.
This will present you with an edit screen like the one shown below.
If you navigate to the I/O tab you will see options for stdin , stdout and stderror streams. These are used mainly on *NIX based systems, but node.js provides some implementation of them and so does nssm . If you provide a path to a .txt file like shown above (although I forgot to add the extension), save and restart your Node-RED service, the files will be created and any console output from Node-RED will be redirected to the file specified, e.g.:
Hopefully Node-RED will provide you with some reason for failure in this file that will make troubleshooting a lot easier.
Please do not forget to run nssm edit node-red again once you have resolved your issue, and remove these values.
Conclusion
Node-RED is an amazing tool, and opens up a ton of possibilities through a simple drag and drop UI. There is a lot more to Node-RED that initially meets the eye, and coupled with something like MQQT gives you so much more power.
Below is the controller flow, and UI designed with Node-RED to control a MP3 player board via an ESP8266 (post coming soon)
Richard Niemand
Read more posts by this author.
Share this post
Changing Sonoff Firmware (Visual Guide)
About a year ago I discovered Sonoff WiFi switches on AliExpress and was able to pick up a couple…
Running Mosquitto as a Windows Service
In my last post I ran over the required steps to get mosquitto up and running on a Windows…
Running on Windows
This page gives specific instructions on setting up Node-RED in a Microsoft Windows environment. The instructions are specific to Windows 10 but should also work for Windows 7 and Windows Server from 2008R2. It is not advisable to use versions prior to Windows 7 or Windows Server 2008R2 due to lack of current support.
Quick Start
1. Install Node.js
Download the latest 12.x LTS version of Node.js from the official Node.js home page. It will offer you the best version for your system.
Run the downloaded MSI file. Installing Node.js requires local administrator rights; if you are not a local administrator, you will be prompted for an administrator password on install. Accept the defaults when installing. After installation completes, close any open command prompts and re-open to ensure new environment variables are picked up.
Once installed, open a command prompt and run the following command to ensure Node.js and npm are installed correctly.
Using Powershell: node —version; npm —version
Using cmd: node —version && npm —version
You should receive back output that looks similar to:
2. Install Node-RED
Installing Node-RED as a global module adds the command node-red to your system path. Execute the following at the command prompt:
3. Run Node-RED
Once installed, you are ready to run Node-RED.
Alternative Installations on Windows
In this section, we provide you with information on alternative ways to install Node.js, npm and the Windows Build Tools needed to install some Nodes for Node-RED on Windows.
Standard installations of Node.js on Windows require local administrator rights. Download the appropriate version from the official Node.js home page. It will offer you the best version. While you can use either 32 bit or 64 bit versions on 64 bit Windows, it is recommended to use the 64bit version of Node. If for some reason, you need a different installation, you can use the Downloads Page.
There are two potentially useful alternatives to installing Node.js with the MSI installer.
Using the Chocolatey package manager
Chocolatey is a package manager for Windows similar to APT or yum on Linux and brew on the Macintosh platforms. If you are already using Chocolatey, you may want to use this tool to install Node.js (e.g. using the nodejs-lts package). Note however, that many packages have uncertain management and that these packages may use different folder locations than those mentioned above.
Using a Node version manager
Using a Node.js version manager such as nvm-windows can be very helpful if you are doing Node.js development and need to test against different versions. Keep in mind that you will need to reinstall global packages and may need to re-install local packages when when you switch the version of Node you are using.
npm on Windows
When you install Node.js, you are also installing the npm package manager. You may see some instructions on the web that recommend installing later releases of npm than the one that comes with the Node.js release. This is not recommended as it is too easy to later end up with an incompatible version. Node.js releases are very regular and that is sufficient to keep npm updated.
Sharing Node-RED between Users
Node.js is installed into the Program Files folder as you would expect. However, if you install a global package like Node-RED using npm -g , it is installed into the $env:APPDATA\npm folder ( %APPDATA%\npm using cmd) for the current user. This is less than helpful if you are installing on a PC with multiple user logins or on a server and installing using an admin login rather than the login of the user that will run Node applications like Node-RED.
To fix this, either give permissions to the folder to other users and make sure that the folder is included in their path user environment variable.
Alternatively, change the global file location to somewhere accessible by other users. Make sure that you use the user that will be running Node-RED to make these changes. For example, to change the location to $env:ALLUSERSPROFILE\npmglobal using PowerShell:
You will then want to change the npm cache folder as well:
If using the above changes, you can add the new prefix folder to the PATH System variable and remove the old folder from the user’s Path variable. To change the PATH Environment variable, type environment into the start menu or Cortana and choose Edit Environment Variables.
For each of the users running Node-RED, check that the above settings for the other users are correct.
Installing Node.js Windows Build Tools
Many Node.js modules used by Node-RED or installed nodes have binary components that will need compiling before they will work on Windows. To enable npm to compile binaries on the Windows platform, install the windows-build-tools module using the command prompt as an Administrator:
If you wish to have the built-in Python v2.7 install exposed for use, use the command:
Running on Windows
Once installed, the simple way to run Node-RED is to use the node-red command in a command prompt: If you have installed Node-RED as a global npm package, you can use the node-red command:
This will output the Node-RED log to the terminal. You must keep the terminal open in order to keep Node-RED running.
Note that running Node-RED will create a new folder in your %HOMEPATH% folder called .node-red . This is your userDir folder, think of it as the home folder for Node-RED configuration for the current user. You will often see this referred to as
/.node-red in documentation.
is shorthand for the user home folder on Unix-like systems. You can use the same reference if using PowerShell as your command line as recommended. If you are using the older cmd shell, that won’t work.
You can now create your first flow.
Using PM2
If you are using Windows to develop Node-RED flows or nodes, you may find it helpful to use PM2 to run Node-RED. This can be configured to automatically restart when files change, always keep Node-RED running and manage log output.
Run Node-RED on Startup
If you want to use Windows as a production platform for Node-RED, you will want to have a Windows Task Scheduler job set up. To do so:
- Go to the start menu and type “task scheduler” and click on the result.
- Click on “Create Task…” in the right-hand menu. Follow the steps to create a new task.
Make sure that you use the user login that you’ve used to set up and do the initial run of Node-RED. You can use an “At startup” trigger to always run Node-RED at system startup. Use the Action “Start a program” with details set to C:\Users\ \AppData\Roaming\npm\node-red.cmd (replacing with your actual user name).
You may wish to make sure that it only starts if the network is available. You may also wish to restart if the job fails. Perhaps restarting every minute but only 3 times — if it won’t start by then, the error is fatal and will need some other intervention. You can check for failures by looking in the event log. If you want to access to the logs when running this way, you should amend the node-red.cmd file to redirect std and error outputs to a file (creating an alternative startup file would be better so that it isn’t overwritten on updates).
Node-RED: Low-code programming for event-driven applications.