You can achieve this in Node-Red by using the file module to read the files one by one, and the fs module to iterate over the files in the directory.
Here's an example flow that should do what you're looking for:
[](https://flows.nodered.org/f/6f53a5484367457f905674222553834f1)
In this flow, the file module is used to read the files one by one, and the fs module is used to iterate over the files in the directory. The foreach loop is used to process each file, and the file.readLine() method is used to read each line of the current file. The line variable is then sent through a process node, which can be a custom node that performs the desired processing on each line.
The file.close() method is used to close the current file when all its lines have been processed, and the fs.readdir() method is used to get the next file in the directory. The file.open() method is used to open the next file, and the process starts again.
Here's the code for the flow:
[
{
"id": "file-reader",
"type": "file",
"filename": "/path/to/directory",
"glob": "**/*.txt",
"interval": 1000
},
{
"id": "foreach",
"type": "foreach",
"collection": "file-reader",
"iterate": "file"
},
{
"id": "file-lines",
"type": "file",
"filename": "%FILE%",
"readline": true,
"separator": "\n"
},
{
"id": "process-line",
"type": "process",
"command": "node -e 'console.log(require(\"util\").inspect(%line%))'"
},
{
"id": "close-file",
"type": "file",
"filename": "%FILE%",
"close": true
},
{
"id": "get-next-file",
"type": "fs",
"command": "readdir",
"directory": "/path/to/directory"
},
{
"id": "open-next-file",
"type": "file",
"filename": "%FILE%",
"open": true
}
]
In this example, the file-reader node is configured to read the files in the specified directory, and the foreach node is configured to iterate over the files. The file-lines node is used to read the lines of the current file, and the process-line node is used to process each line. The close-file node is used to close the current file when all its lines have been processed, and the get-next-file node is used to get the next file in the directory. Finally, the open-next-file node is used to open the next file, and the process starts again.
Note that this is just an example, and you may need to modify the flow to suit your specific requirements. For example, you may want to add error handling, or modify the process-line node to perform a different operation on each line.