Node-RED is a flow-based development tool for visual programming originally developed by IBM to connect hardware devices, APIs, and online services as part of the Internet of Things.
This article briefly explains how to install Node-Red on Ubuntu 24.04 LTS using NPM with Node.js. We recommend installing the latest version of Node.js, which you can check in its Github repository.
The latest version is currently Node.js v20.x, so we add the repository for that version:
# curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - Then we update the repositories, upgrade packages, and install Node.js:
# apt update && apt upgrade -y && apt install -y nodejsOnce the command has run, we check which versions of Node and NPM have been installed:
# node -v && npm -vInstalling Node-Red:
# npm install -g --unsafe-perm node-redInstalling Node-Red-Admin:
# npm install -g --unsafe-perm node-red-adminNext, generate a hash for the user's password:
# node-red admin hash-pw You will be prompted to enter the password you want to use. Remember to save the hash to add it to the configuration file later, but you can test Node-Red with:
# node-redTo test it, use a browser and enter the URL http://dirección_IP_servidor:1880. Remember to keep the default Node-Red port (1880 TCP) open in the Firewall profile assigned to the server.
The Node-Red login should appear in the browser:
Then stop the process with "Ctrl+C" to edit the configuration file to enable HTTPS, uncomment the authentication lines, and add the password hash.
To enable HTTPS, you need a certificate with its corresponding key. You could configure a reverse proxy with Apache or NGINX to use Certbot for automatic configuration and renewal.
However, you can simply choose to use a self-signed certificate; to do so, you can run the following:
# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/selfsigned.key -out /etc/ssl/certs/selfsigned.crt
Once you have entered the details and generated the files, edit the configuration file:
# vi /root/.node-red/settings.jsIn the https section, you must uncomment it and add the paths:
https: {
key: require("fs").readFileSync('/etc/ssl/private/selfsigned.key'),
cert: require("fs").readFileSync('/etc/ssl/certs/selfsigned.crt')
},
Then do the same with the adminAuth section. It should look similar to the following content (remember to replace the hash with the generated hash):
/** To password protect the Node-RED editor and admin API, the following
* property can be used. See http://nodered.org/docs/security.html for details.
*/
adminAuth: {
type: "credentials",
users: [{
username: "admin",
password: "$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.",
permissions: "*"
}]
},
You could also add another user, for example, a read-only user (optional):
/** To password protect the Node-RED editor and admin API, the following
* property can be used. See http://nodered.org/docs/security.html for details.
*/
adminAuth: {
type: "credentials",
users: [{
username: "admin",
password: "$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.",
permissions: "*"
},
{
username: "invitado",
password: "$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.",
permissions: "read"
}]
},
Then, to test the credentials, you can start it again ("Ctrl+C" to stop it):
# node-red -vOnce you have verified that the credentials work, you can use a service to start Node-Red automatically when the operating system starts with systemd. To do this, create the service file:
# vi /etc/systemd/system/Node-Red.serviceThis service file should contain the following:
# This script works on any system using systemd as the init process.
# It works on Ubuntu Focal.
# If you have Debian/Raspbian Wheezy and want to use this script with systemd
# follow the information here : https://wiki.ubuntu.com/systemd
# To consult the log : journalctl -u Node-RED
[Unit]
Description=Node-RED is a tool for wiring together hardware devices, APIs and
online services in new and interesting ways.
After=syslog.target network.target
Documentation=http://nodered.org/
[Service]
Environment="NODE_OPTIONS="
Environment="NODE_RED_OPTIONS=-v"
#Full Path to Node.js
ExecStart=/usr/bin/node-red $NODE_OPTIONS $NODE_RED_OPTIONS
WorkingDirectory=/root/.node-red/
# User/Group that launches node-RED (it's advised to create a new user for Node-RED)
# You can do : sudo useradd node-red
# then replace User=root with User=node-red
User=root
Group=root
Nice=10
SyslogIdentifier=Node-RED
StandardOutput=syslog
# Make Node-RED restart if it fails
Restart=on-failure
# Node-RED needs a SIGINT to be notified to stop
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
Finally, reload the daemons, enable the service, start it, and check its status:
# systemctl daemon-reload && systemctl enable Node-Red.service && systemctl start Node-Red.service && systemctl status Node-Red.service
We hope this tutorial has helped you. Have you tried it? Leave us your comments! 🙂
Remember, if you have any questions about this or any other issue related to your servers on Clouding, feel free to write to soporte@clouding.io We're here for whatever you need!