Watch node producing 2 payloads upon file creation


I have a simple test flow to demonstrate my problem. This is my flow

[{"id":"d32c1f48.87f48","type":"tab","label":"Test flow","disabled":false,"info":""},{"id":"8c67530a.53a1f","type":"inject","z":"d32c1f48.87f48","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":319.5,"y":239,"wires":[["ef562e25.8545e"]]},{"id":"ef562e25.8545e","type":"function","z":"d32c1f48.87f48","name":"","func":"msg.payload = { \"adapterId\": \"0050c07cf4\", \"deviceId\": \"0022092258389225\", \"deviceType\": \"Blood-Pressure\", \"dateRecorded\": \"2018-12-18 11:57:44\", \"client\": \"raspberry\", \"properties\": [ { \"code\": \"sys\", \"unit\": \"mmHg\", \"value\": \"132.000000\" }, { \"code\": \"dia\", \"unit\": \"mmHg\", \"value\": \"85.000000\" }, { \"code\": \"pulse\", \"unit\": \"mmHg\", \"value\": \"100.000000\" } ]};\nreturn msg;","outputs":1,"noerr":0,"x":469,"y":241,"wires":[["3377130a.538fcc"]]},{"id":"3377130a.538fcc","type":"file","z":"d32c1f48.87f48","name":"","filename":"/home/pi/Desktop/JsonFiles/test.json","appendNewline":true,"createDir":false,"overwriteFile":"true","x":728.5,"y":244,"wires":[]},{"id":"6ea3ecd4.894714","type":"debug","z":"d32c1f48.87f48","name":"debugger","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":650.5,"y":125,"wires":[]},{"id":"c163c369.5e44b","type":"watch","z":"d32c1f48.87f48","name":"","files":"/home/pi/Desktop/JsonFiles/","recursive":"","x":344.5,"y":129,"wires":[["6ea3ecd4.894714"]]}]

When i create a new file watch node fires 2 events instead of 1 (the creation of the file). The weird thing is that the size of the file on the first event is showing as 0 and on the second event is the real size . What am i missing?



Can confirm. On top of that, if using option "append to file", sometimes there is no output at all. By opening manually the file, output fires also. Sounds like little bug.

18 Dec 08:59:14 - [info] Node-RED version: v0.20.0-beta.2
18 Dec 08:59:14 - [info] Node.js  version: v8.11.3
18 Dec 08:59:14 - [info] Windows_NT 10.0.17134 x64 LE

That is expected. The watch node gets file system events. There are two events - the file was created and the file was written to.


ok so the only obvious way to catch the wanted event is to use a switch node with msg.size property set to what you want? I would like to know cause some times only 1 event is fired and i am really confused.

EDIT : most of the times the event of file creation is fired only. Correct me if i am wrong but i have noticed that when there is only 1 file in the folder only 1 event is fired , if i add more files both events are fired as expected.