Hi!
I'm trying to append file with text on local file system.
Here is a duplicate, but there is no solution: File node not working on windows
Here's my first try. I wrote file name in property filename of node file:
[{"id":"80d649c2.f66f58","type":"inject","z":"3aaeeceb.d5ae64","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":100,"wires":[["84711ac0.43a1f8"]]},{"id":"84711ac0.43a1f8","type":"function","z":"3aaeeceb.d5ae64","name":"format DateTime","func":"return new Date(msg.payload);","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":100,"wires":[["761c3f2a.4c002","a936aca1.2db3a"]]},{"id":"668c5ac4.ef8b34","type":"debug","z":"3aaeeceb.d5ae64","name":"file node output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":840,"y":100,"wires":[]},{"id":"761c3f2a.4c002","type":"file","z":"3aaeeceb.d5ae64","name":"","filename":"D:\\test\\nodered.txt","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"utf8","x":610,"y":100,"wires":[["668c5ac4.ef8b34"]]},{"id":"a936aca1.2db3a","type":"debug","z":"3aaeeceb.d5ae64","name":"before writing into file","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":360,"y":160,"wires":[]},{"id":"3fe82c65.0b0894","type":"catch","z":"3aaeeceb.d5ae64","name":"","scope":null,"uncaught":false,"x":640,"y":140,"wires":[["db53f5db.f4e7b8"]]},{"id":"db53f5db.f4e7b8","type":"debug","z":"3aaeeceb.d5ae64","name":"catch error","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":140,"wires":[]}]
Also I tried to write path as D:\\test\\nodered.txt
and D:/test/nodered.txt
, but it didn't work. Catch node didn't catch anything.
Why doesn't it work?
My second try was without setting filename property in node, but in msg that file node receive. Here it is:
[{"id":"80d649c2.f66f58","type":"inject","z":"3aaeeceb.d5ae64","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":180,"wires":[["84711ac0.43a1f8"]]},{"id":"84711ac0.43a1f8","type":"function","z":"3aaeeceb.d5ae64","name":"add filename to msg","func":"return {\n payload: new Date(msg.payload),\n filename: \"D:\\\\test\\\\nodered.txt\",\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":180,"wires":[["761c3f2a.4c002","a936aca1.2db3a"]]},{"id":"668c5ac4.ef8b34","type":"debug","z":"3aaeeceb.d5ae64","name":"file node output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":960,"y":180,"wires":[]},{"id":"761c3f2a.4c002","type":"file","z":"3aaeeceb.d5ae64","name":"","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"utf8","x":770,"y":180,"wires":[["668c5ac4.ef8b34"]]},{"id":"a936aca1.2db3a","type":"debug","z":"3aaeeceb.d5ae64","name":"before writing into file","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":480,"y":240,"wires":[]},{"id":"3fe82c65.0b0894","type":"catch","z":"3aaeeceb.d5ae64","name":"","scope":null,"uncaught":false,"x":760,"y":220,"wires":[["db53f5db.f4e7b8"]]},{"id":"db53f5db.f4e7b8","type":"debug","z":"3aaeeceb.d5ae64","name":"catch error","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":950,"y":220,"wires":[]}]
And it works. Why?