Read From The Server Flow
Introduction
This flow is part of our Input flows collection. Input flows are used for importing data inside Node-RED for further processing.
This example flow shows you how to read files from a Node-RED container within Node-RED. This method is helpful when you need to work with a large dataset in your project.
Prerequisites
This flow along with its dependencies is available for user in the following package:
@senlab/node-red-input-flow-read-server
To learn more about Verdaccio and how to install packages, please refer to this documentation: Verdaccio
Setting Up The Inject Node
We initiate our flow with the Inject Node, which is a basic node and already preinstalled inside Node-RED. It can be found under the common tab.
The Inject Node can function as a button or a signal generator. Users need to specify which property and value the node will inject into the flow. For the purposes of this flow, the specific configuration of the property and value is not critical, as the primary goal is to activate other nodes within the flow. In the configuration panel, users have the option to set the Inject Node to either inject the value just once or to do so repeatedly at a specified interval.
In this example, you only need to trigger the Inject Node once to read the entire document from the container.
Getting Data with the Read File node
We get file from the container using Read File Node, which is basic node and already preinstalled inside Node-RED. It can be found under the storage tab.
Read File Node requires simple configuration, path and filename need to be specified, in this case it is Iris.data dataset which is used in another example. It is advisable to read and save those files inside data directory, which direcotry inside container mounted to volume, this means that data persists through container restarts. Other two configuration options are output format and encoding, output can be divided into seperate msg objects or it can be passed as one string, encoding can be of choosing.
Sending and testing through MQTT
MQTT is our protocol of choice inside our Node-RED examples and you will see it being used many times. To find out what MQTT is and how to use it in the scope of Node-RED check this documentation: …
MQTT Node uses outMSG variable to be sent out as message body, in this case previously created object needs to be assigned to the outMSG variable.
MQTT is used to send this file to other flows or services running on Sandbox, MQTT subscribe Node is used to test if the message is published in desired form.