Install Node-RED and an MQTT broker on your server

Node-RED runs on any CheapVPS server with Node.js 22 LTS (or 20 LTS) installed, either as a global npm package under systemd or as the official Docker image. Protect the editor with adminAuth and a bcrypt hash, put Nginx in front with websocket headers and HTTPS, and run Mosquitto beside it when your devices speak MQTT. S4 or P2 handle typical automation flows.

Self-hosted apps guide, updated 2026-12-03

Why host Node-RED on a VPS rather than at home?

Node-RED is a flow-based programming tool: you wire nodes together in a browser editor to receive webhooks, poll APIs, transform JSON, write to databases and publish MQTT messages. A home Raspberry Pi works well for local sensors, but a server with a public IPv4, a static IPv6 /64 and steady power is better for anything that must answer webhooks from the internet, talk to cloud APIs on a schedule or collect data from devices in several places.

The console has no Node-RED image. Start from Ubuntu 24.04 for the npm method or from Docker CE for containers. Both are covered below, and the rest of the guide (login, proxy, MQTT, backups) is the same for either.

Which plan and city fit an automation server?

Node-RED itself is light: an idle instance uses roughly 80~150 MB of RAM. Your flows decide the rest. Large function nodes, dashboards with many charts and in-memory context data add up.

WorkloadPlanSpecs
Webhooks, a few schedules, small MQTT brokerS42 vCPU, 4 GB RAM, 40 GB NVMe
Any region, dozens of flows plus a dashboardP21 vCPU, 2 GB RAM, 40 GB NVMe
Node-RED with InfluxDB or PostgreSQL on the same boxP42 vCPU, 4 GB RAM, 80 GB NVMe
Low power draw, Arm builds, EuropeA42 vCPU, 4 GB RAM, 40 GB NVMe

Pick the city nearest the APIs and devices you talk to. A flow that calls an API in Asia every few seconds runs best from Singapore or Tokyo; European sensors fit Frankfurt or Amsterdam. Prices match in every city.

Which DNS records should you create?

Use one name for the editor and, if devices connect from outside, one for MQTT. For example flows.example.com and mqtt.example.com, both as A records to 203.0.113.10 and AAAA records to 2001:db8:1234:5678::1. They can point at the same server; separate names simply let you move the broker later without reconfiguring every device. Verify with dig +short flows.example.com before you request certificates.

How do you install Node.js and Node-RED with npm?

Ubuntu 24.04 ships Node.js 18 in its own archive, which is older than current Node-RED releases want. Install the 22 LTS line from the NodeSource repository:

apt update && apt install -y curl ca-certificates build-essential
curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh
bash nodesource_setup.sh
apt install -y nodejs
node -v   # v22.x

Use setup_20.x if a node you depend on still targets Node 20. On Rocky or Alma Linux the same script exists as https://rpm.nodesource.com/setup_22.x and you finish with dnf install nodejs.

Run Node-RED as its own user, never as root:

useradd -m -s /bin/bash nodered
npm install -g --unsafe-perm node-red

Create /etc/systemd/system/nodered.service:

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

[Service]
Type=simple
User=nodered
WorkingDirectory=/home/nodered
Environment="NODE_OPTIONS=--max-old-space-size=512"
ExecStart=/usr/bin/node-red --max-old-space-size=512 -u /home/nodered/.node-red
Restart=on-failure
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

Then systemctl daemon-reload && systemctl enable --now nodered. The first start creates /home/nodered/.node-red/ with settings.js and, after your first deploy, flows.json and flows_cred.json. Adjust the memory limit to about half the plan RAM. The Node-RED project also publishes an install script for Debian-based systems that does all of this in one go; the manual steps above show you what it changes.

How do you run Node-RED with Docker instead?

On the Docker CE image, a named volume holds flows, credentials and installed nodes:

services:
  nodered:
    image: nodered/node-red:latest-22
    restart: unless-stopped
    environment:
      - TZ=Europe/Berlin
    ports:
      - "127.0.0.1:1880:1880"
    volumes:
      - nodered_data:/data
volumes:
  nodered_data:

Start with docker compose up -d. Inside the container the user directory is /data, so settings.js lives in the volume (docker volume inspect nodered_data shows the host path). Extra nodes installed from the palette manager are stored there too and survive image updates. Binding to 127.0.0.1 matters: Docker publishes ports around ufw, and an editor on a public port is an open door.

How do you protect the editor with adminAuth?

By default the editor has no login. Generate a bcrypt hash of a strong password:

sudo -u nodered node-red admin hash-pw
# Docker: docker compose exec nodered node-red admin hash-pw

Paste the result into settings.js by uncommenting the adminAuth block:

adminAuth: {
    type: "credentials",
    users: [{
        username: "admin",
        password: "$2b$08$REPLACE_WITH_YOUR_HASH",
        permissions: "*"
    }]
},
credentialSecret: "a-long-random-string",
uiHost: "127.0.0.1",

credentialSecret encrypts flows_cred.json; keep a copy, because flows restored without it lose their stored API keys and passwords. uiHost keeps the editor on localhost for the npm install (leave it out in Docker, where the port binding already does this). If you serve HTTP endpoints or a dashboard to others, add httpNodeAuth with its own hash. Restart with systemctl restart nodered.

How do you proxy the editor with websockets and HTTPS?

The editor keeps a websocket open to /comms for live status; without the upgrade headers the page loads but shows a lost connection banner. Nginx site file:

server {
    listen 80;
    listen [::]:80;
    server_name flows.example.com;
    location / {
        proxy_pass http://127.0.0.1:1880;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 86400;
    }
}

Enable it and add a certificate with certbot --nginx -d flows.example.com. Nginx with HTTPS explains renewal. The long read timeout keeps idle websockets from being cut every minute.

How do you run Mosquitto next to Node-RED?

Mosquitto is a small MQTT broker. Install it with apt install -y mosquitto mosquitto-clients. Since version 2.0 it only accepts local, anonymous clients until you configure a listener, which is a safe default. Create a password file and a config:

mosquitto_passwd -c /etc/mosquitto/passwd sensor1
mosquitto_passwd /etc/mosquitto/passwd nodered
chown root:mosquitto /etc/mosquitto/passwd && chmod 640 /etc/mosquitto/passwd

/etc/mosquitto/conf.d/main.conf:

listener 1883 127.0.0.1
listener 8883
certfile /etc/mosquitto/certs/fullchain.pem
keyfile /etc/mosquitto/certs/privkey.pem
allow_anonymous false
password_file /etc/mosquitto/passwd
persistence true

Copy the certificate for mqtt.example.com into /etc/mosquitto/certs/ (a Certbot deploy hook can do this on every renewal, followed by systemctl reload mosquitto). Node-RED connects locally on 1883; devices connect over TLS on 8883. Test with mosquitto_sub -h 127.0.0.1 -u nodered -P yourpass -t test/# in one window and mosquitto_pub in another.

Which ports should the firewall allow?

ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 8883/tcp   # MQTT over TLS for devices
ufw enable

Keep 1880 and 1883 closed to the outside: the editor goes through Nginx and plain MQTT stays on localhost. Use the firewall guide for firewalld on Rocky or Alma.

How do you update, keep flows safe and fix common problems?

Updating. For npm: npm install -g --unsafe-perm node-red then systemctl restart nodered. Update installed nodes from the palette manager or with npm update inside ~/.node-red. For Docker: docker compose pull && docker compose up -d. Node.js itself updates with apt upgrade.

Persistent flows and backups. Everything that matters sits in the user directory: flows.json, flows_cred.json, settings.js, package.json (your installed nodes) and the context folder if you enabled file-backed context storage with contextStorage: { default: { module: "localfilesystem" } }. Turn on Projects in settings.js to keep flows in Git, and copy the directory nightly with restic or rsync. Mosquitto keeps retained messages in /var/lib/mosquitto/mosquitto.db. The disk backup add-on ($0.85 per month on S4) adds 7 daily copies; see backups and restore.

Troubleshooting. journalctl -u nodered -f shows node errors live. A crash loop after installing a node usually means a native module built for another Node version; run npm rebuild in the user directory. "Lost connection to server" in the editor points at missing websocket headers. MQTT clients that fail with "not authorised" have a wrong password or a password file Mosquitto cannot read.

Questions about this guide

Node.js 20 or 22 for Node-RED?

Both are LTS lines and work. Choose 22 for a new install unless a specific node you rely on lists only 20.

Can Node-RED run on an Arm server?

Yes. Node.js and the Docker image both support arm64, so A4 in Frankfurt, Nuremberg, Helsinki or Amsterdam is a good fit. Nodes with native code compile for Arm during install.

How do I reset a forgotten editor password?

Generate a new hash with node-red admin hash-pw, replace it in settings.js and restart the service.

Can devices connect over websockets instead of 8883?

Yes. Add a listener 9001 with protocol websockets in Mosquitto, proxy it through Nginx on 443 and open nothing else.

Will my flows survive a container update?

Yes, as long as /data is a volume. Pulling a new image replaces the program, not the volume.

Can I run several Node-RED instances on one server?

Yes. Give each its own user directory and port (-p 1881, -p 1882) and its own Nginx server block.