Read File from Watch

#1

I created a watch that creates a payload like "\\serverName\AppDrive\temp\test.log"

I want to now read the contents of that file. I tried using the file by line node but how do I identify the filepath is the msg.payload from the watch step?

#2

Input of file in node should be carried by msg.filename
Watch node puts the file path to the msg.payload
You'll need a change node to move property from msg.payload to msg.filename

1 Like
#3

hmm - that would be improved if the watch node also set msg.filename .

2 Likes
#4

Thank you for your assistance. Would you be able to tell me what I put in the file-by-line node file box? I tried {{msg.payload}} and msg.payload but the debug output threw me an error:

"Error: ENOENT: no such file or directory, open 'E:\Program Files\npm\node-red-master{{msg.payload}}'"

"Error: ENOENT: no such file or directory, open 'E:\Program Files\npm\node-red-master\msg.payload'"

I tried to pass msg.filename as well:
"Error: ENOENT: no such file or directory, open 'E:\Program Files\npm\node-red-master\msg.filename'"

I also tried to leave it blank.
image

image

#5

Ah - you are using a 3rd party node... not one I've used.
The built in file in node can also be set to send a line at a time...

#6

Looking at HipNipi's response, he pointed out I need to move property. I updated that and then used the built in file in node. Do I leave the Filename blank on the file in node? It has an output of undefined.

My msg.payload shows the correct file path on the watch but I am missing something when sending it to file in node.

image

image

#7

msg.filename needs to contain the absolute path and the filename.

Then yes leave the filename setting in the nodes config page empty.

If this isn’t working add some debug nodes set to output entire message along your flow

#8

Thanks for the suggestions. I got it working! I added a debug on the end of the file in node and I see it is actually getting the data. :slight_smile: