Read data from a .txt-file with 'file in'-node

Hey everyone,

sorry for the kind of 'basic' question. I didn't find it anywhere and I am doin my first steps with Node-RED.

My Problem:
I am watching a folder (wfwatch-Node). Everytime a new document (.txt) is created in that folder, i want to read that document (if its a new one). I tried it with the 'file in' node. It didn't work.

Could sombody tell me what I am doin wrong?

image

Thanks a lot!

Which bit didn't work ?
Did you try triggering the file read from an inject node ?
How do you have the file node configured ?
What is the switch doing ?
etc

put some more debug nodes into your flow to see what messages are being passed.

From the screenshot it looks like you have hard coded to file name in the file node. If you read the info panel for the file node it will tell you where the file name needs to be. you will need a change node to move the file name to the correct place

Thank you for your help.

  1. Not sure what you mean. (the whole thing didn't work)
  2. No i did not. I dont think this would solve the problem.
  3. I put in the filenamepath
  4. The switch-Node is checking, if something new is 'created' in the folder.

Thanks a lot for your help.

I read it. It said 'The filename should be an absolute path'.

I tried to change it. But it still doesen't work.

I get this error now.

Ah right, on windows you may need to escape the \ with another \. So c:\\Users\\.... Etc

so as I said add debug nodes along your flow to see what messages are actually being passed.

If you want to pass the file name and path within the message being passed between the nodes it has to be in the correct position.
I’m not at my computer but I thought this was something like msg.filename but it is specified in the info panel
You must then leave the filename in the config panel blank
But as the watch node outputs the filename as msg.payload you will need to move it as well as the modification that ceejay suggested

Node red is a block structured system. To say the whole thing doesn't work doesn't really make sense, some nodes are probably working, but are not getting the right data. What I think you mean is that as a complete system you are not getting out what you expect. As others have suggested, the debugging technique to use is to start at the beginning of the flow (in this case the watch node) and put a debug node on the output of that and make sure that you are seeing what you expect. Once that is working then put a debug on the output of the next node and check that is working as expected. Follow this technique right through and flow and eventually you will get it all working, or you will come across one node that you can't fix, then you can come back and ask again.

One question, while i have successfully stored a payload object in a text file, when i paste this payload to a change node under JSON which is then triggered from a worldmap in function through a switch i have my points on map everytime i refresh the page. NOW when i trigger this file in with a switch node or an inject and then to the worldmap i get nothting there. Its strange as already the subject is stored to the said file. What am doing wrong to worldmap in → switch → file in → worldmap. what i want is to retain my objects on the map after a new user gets it or i refresh


is my switch node configured correctly to inject/trigger my file to world map?

Payload is a string. Pass it through a JSON node to convert it to a JS object. Then you can access is properties.

Thank you Steve, i thought the other way around. Thought the payload was a JS object and through the function node and the variable "payload" : JSON.parse(JSON.stringify(data)) it convert it of what the worlmap want to see. Thanks for the clarification and solution!!

Hey guys! kind of off topic and a silly question.... I can not seem to find File in within the Palette anywhere? where are you guys finding it? i have searched for hours...

Thanks in advance :smiley:

Hi what platform are you on ?
The file in node is hidden on IBM Cloud as the concept of a file system makes little sense.

1 Like

Oh I am using IBM Cloud.. does this mean I won't be able to access it? apologies i am just learning and wrapping my head around all of this.

If you were able to use it, where would the file you want to read be stored so that you can read it? Remember that the server runs in the cloud not in the PC running the browser, so it can't access files on the PC.