Like most things with Node-RED there are many ways to do the same thing.
Here is how I build my reports to send via email…
The switch node in this case is optional, its just how I trap for a key word that I want to log to my file.
The cool stuff is in the date/time formatter node aka the ‘Moment’ node. Note, you will need to install this node since its not a core node.
What we are doing here is building the file name that will be used to write the file to the hard drive in the computer.
It will automatically roll over at midnight and so you will end up with 1 file per day all in the file path that you hard code into the node.
One thing to note, its critical that you use the correct ‘Output Tz’ name. You can find your TZ database name from the list.
Note that in this screen shot, I am running Node-RED on a Windows PC, so the path will need to be changed to match your platform and file path you want your data logged.
Best practices dictates that you should NOT have any spaces in your file name.
The file node is very straight forward;