Install Node-RED using Docker and NgrOK tunnel
Using Docker brings many advantages when you want a fast deployment of the Node-RED, as you can do it with just a few clicks on your computer.
You can also deploy Node-RED on IBM Cloud, Horeku, Fly.io, or whatever is capable of hosting web apps, Docker containers, and Linux servers.
Check: Install NodeJS, NPM, and Node-RED on Raspberry Pi OS Lite 64-bit
Deploy using Docker Desktop
For short, using Docker:
- Download and install Docker Desktop;
- Open the Docker Desktop, and, using the 🟩 search bar above, find “nodered/node-red”;
- Run 🟪 it like a boss 😎!
- At optional settings, 🟧 bind the 1880 container port to the 1880 port, at “Volumes”, 🟨 pick a host folder, e.g. “C:\Node-RED data” for storing Node-RED data, and bind it to the /data inside the container;
- You should be able to access Node-RED at http://localhost:1880/ 😃.
Note: Next time you want to start the Node-RED 🟥, don’t search again and run the image, instead start the container that was created!
Secure the Node-RED access
You can freely use the Node-RED over the internet without a prompt for username or password, or some other sort of authentication, which isn’t the desirable way.
To use the basic authentication, you gotta edit the configuration of the Node-RED. To do this, access the Node-RED data folder on the host, defined at the “Volumes” above, e.g. 🟨 “C:\Node-RED data” and open the “settings.js” with a text editor.
Uncomment the 🟧 “adminAuth:” section and change the username and password as you wish. You can get the password hash in bcrypt algorithm using this website or by using the node-red admin hash-pw
from Terminal.
Now restart just the 🟩 Node-RED docker container and you should see the authentication prompt when you connect again to the Node-RED.
NGROK with Node-RED
To use Facebook Messenger or WhatsApp Business API, you need a valid non-self-signed certificate to use your link to the Node-RED as a webhook.
You don’t need to do this if you deploy on a platform that is listed above (e.g. IBM), as you probably already can access Node-RED over https:// .
If you chose the Docker installation above, the easiest way to get a secure connection to your container is to add a ngrok container:
- Open a Terminal, CMD, or Powershell;
- Copy the auth token 🟩 from the ngrok website to container settings as a variable 🟧 “NGROK_AUTHTOKEN”;
- Run the command:
docker run --name ngrok-nodered -e NGROK_AUTHTOKEN=YOUR_TOKEN_HERE ngrok/ngrok:latest http host.docker.internal:1880 --region us
Use the US as the region for NgrOK to don’t get blocked from META.
Now you should be able to access Node-RED over the web using the specified URL from NgrOK. You find this 🟨 URL by accessing the “Agents” section of the website.
Note: Next time, you can simply start the NgrOK Docker container from 🟧 Docker Desktop and find the URL on the ngrok website.
IMPORTANT! ngrok URL will be changed at every container start. If you plan to use this for production or longer term than a few days, you should consider alternatives, like free: port-forwarding, dynamic DNS, and certbot, or upgrade the ngrok to pro and get a reserver hostname. It only affects Facebook Messenger and WhatsApp, not Telegram (if you don’t use Telegram through Webhook, which is not the case here).
Great
Now it’s time to create something amazing 😀.