Node-RED is a popular tool for quickly putting together experiments and integrations. Data Connectors work out of the box with Node-RED using an HTTPS endpoint, but this requires the Node-RED installation to be reachable from the internet. If you are hosting the Node-RED instance with a cloud provider such as IBM Bluemix, you are ready to go.
If you want to run Node-RED behind your company firewall however, you need to set up a pipe from the internet to your instance. This example shows how you can quickly get such a set up running.
Using port forwarding service
We are going to use the ngrok service, which provides a flexible solution for setting up a port forward from an internal endpoint to a protected endpoint reachable from the internet.
The ngrok service has a free tier that is sufficient for prototyping small scale solutions.
1. Install Node-Red locally on your computer
We will assume that you have Node-RED running on your computer already. If not visit the node-RED website to get the machine setup.
2. Install ngrok and signup for a free account
Go to https://www.ngrok.com signup and follow the instructions to download the ngrok client.
The tool is possible to use without an account, but then you will not be able to set a username and password on the endpoint. Remember to run command to set the token received after signup:
./ngrok authtoken <YOUR_TOKEN>
3. Create the Node-RED flow
- Start Node-RED and notice the port number
- Create a Node-RED flow with an HTTP endpoint
- Drag an HTTP node into the flow, double-click on it, and define a POST endpoint like below.
- Drag in a http-response node, make it say “200 OK” and connect the nodes
- Drag a debug-module in to show that events appear
- Click on Deploy in the top right corner
- Switch to the debug tab
4. Forward Node-RED port to outside the firewall
Run ngrok for the Node-red install - get an internet reachable endpoint. Notice that we only want https at the internet-side and using basic auth to protect it
ngrok http -bind-tls=true -auth "<username>:<password>" 1880
username and password can be set freely.
5. Set up a Data Connector to push to the provided ngrok address
- Open the project with your sensors that you wish to receive data from.
- Go to Data Connectors and click Add to create a new connector
From the console where you are running ngrok, extract the “Forwarding” server. It will look something like https://ae573ff6.ngrok.io.
Use the username/password from above and the forwarding ngrok server to create the URL in the picture:
Save the Data Connector, press a sensor and you should see events pouring into the debug panel.