# How to set the output-property of the file-read node with a function node?

**URL:** <https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686>\
**Category:** General\
**Created:** [20 February 2022 12:09 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686 "2022-02-20T12:09:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliver](https://avatars.discourse-cdn.com/v4/letter/o/85f322/32.png) [@oliver](https://discourse.nodered.org/u/oliver)\
**Post date:** [20 February 2022 12:09 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/1 "2022-02-20T12:09:11Z")

</div>

For a multipage node-red webserver, serving stored html pages and images, the function node should set the output-property of the file-read node to text or buffer, depending on reading and serving html or images.

Now I use 2 file-read nodes with different output, one for text and one for images and that works but if possible I would prefer to use only 1.

How to set that property from a function node placed in the flow before the file-read node? Thx.

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [20 February 2022 14:54 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/2 "2022-02-20T14:54:15Z")

</div>

Something like this:

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/599af57140b471fbeb41f2763b9b13756f50ccbb.png)

```auto
[{"id":"c9d33f11764714ae","type":"switch","z":"dd743d35a9e71eef","name":"","property":"filename","propertyType":"msg","rules":[{"t":"cont","v":".html","vt":"str"},{"t":"cont","v":".png","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":140,"wires":[["94949fd7249f3f39"],["4e9ae86fc66fe2bf"]]},{"id":"94949fd7249f3f39","type":"file in","z":"dd743d35a9e71eef","name":"output text","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":670,"y":100,"wires":[["ec66ab58b3bc740e"]]},{"id":"4e9ae86fc66fe2bf","type":"file in","z":"dd743d35a9e71eef","name":"output buffer","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":670,"y":180,"wires":[["ec66ab58b3bc740e"]]},{"id":"c5c13671f4cd820f","type":"inject","z":"dd743d35a9e71eef","name":"/home/pi/temp/index.html","props":[{"p":"filename","v":"/home/pi/temp/index.html","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","x":250,"y":120,"wires":[["c9d33f11764714ae"]]},{"id":"cf265fa629e194e7","type":"inject","z":"dd743d35a9e71eef","name":"/home/pi/temp/raspberrypi.png","props":[{"p":"filename","v":"/home/pi/temp/raspberrypi.png","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","x":240,"y":160,"wires":[["c9d33f11764714ae"]]},{"id":"ec66ab58b3bc740e","type":"debug","z":"dd743d35a9e71eef","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [20 February 2022 14:56 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/3 "2022-02-20T14:56:39Z")

</div>

Scratch that, I misread the question.

---

<div class="post-metadata">

**Author:** ![oliver](https://avatars.discourse-cdn.com/v4/letter/o/85f322/32.png) [@oliver](https://discourse.nodered.org/u/oliver)\
**Post date:** [20 February 2022 16:48 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/4 "2022-02-20T16:48:03Z")

</div>

Thanks for answering, yes this way I could solve it also, I am new to node-red , so I am not sure if and how every property of a node can be set by a previous one in the flow.  
For example the filename-property of the file-read node could be set, so I was wondering why the output-property could not be set.. but all I tried to do that did not work.  
Can all properties be set in theory?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 February 2022 18:12 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/5 "2022-02-20T18:12:52Z")

</div>

If you look at the help text for the node in the right hand pane after clicking the node, it should tell you what properties you can pass in.

---

<div class="post-metadata">

**Author:** ![oliver](https://avatars.discourse-cdn.com/v4/letter/o/85f322/32.png) [@oliver](https://discourse.nodered.org/u/oliver)\
**Post date:** [20 February 2022 18:42 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/6 "2022-02-20T18:42:58Z")

</div>

Thank you, I guess it are the properties in the read color under the heading Inputs that you mean?  
That means only the filename can be set by other nodes in the flow?

Strange that not all properties can be set, this forces me to use 2 nodes on 2 outputs at the function.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 February 2022 19:01 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/7 "2022-02-20T19:01:43Z")

</div>

What is the difference between the two?

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [20 February 2022 19:03 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/8 "2022-02-20T19:03:55Z")

</div>

I would think it is good practice to let all properties be able to be set by the incoming message, but that is not always the case.

You could create a subflow, with the `switch` node and 2+ `file in` nodes from my example that would handle the task though.

This should handle most files:

```auto
[{"id":"f59e3fa306dac4d1","type":"subflow","name":"Auto File In","info":"","category":"","in":[{"x":80,"y":120,"wires":[{"id":"c9d33f11764714ae"}]}],"out":[{"x":520,"y":120,"wires":[{"id":"94949fd7249f3f39","port":0},{"id":"4e9ae86fc66fe2bf","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"c9d33f11764714ae","type":"switch","z":"f59e3fa306dac4d1","name":"","property":"filename","propertyType":"msg","rules":[{"t":"cont","v":".htm","vt":"str"},{"t":"cont","v":".js","vt":"str"},{"t":"cont","v":".css","vt":"str"},{"t":"cont","v":".php","vt":"str"},{"t":"cont","v":".txt","vt":"str"},{"t":"cont","v":".png","vt":"str"},{"t":"cont","v":".jpg","vt":"str"},{"t":"cont","v":".jpeg","vt":"str"},{"t":"cont","v":".bmp","vt":"str"},{"t":"cont","v":".gif","vt":"str"},{"t":"cont","v":".tif","vt":"str"},{"t":"cont","v":".raw","vt":"str"}],"checkall":"true","repair":false,"outputs":12,"x":190,"y":120,"wires":[["94949fd7249f3f39"],["94949fd7249f3f39"],["94949fd7249f3f39"],["94949fd7249f3f39"],["94949fd7249f3f39"],["4e9ae86fc66fe2bf"],["4e9ae86fc66fe2bf"],["4e9ae86fc66fe2bf"],["4e9ae86fc66fe2bf"],["4e9ae86fc66fe2bf"],["4e9ae86fc66fe2bf"],["4e9ae86fc66fe2bf"]]},{"id":"94949fd7249f3f39","type":"file in","z":"f59e3fa306dac4d1","name":"output text","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":370,"y":80,"wires":[[]]},{"id":"4e9ae86fc66fe2bf","type":"file in","z":"f59e3fa306dac4d1","name":"output buffer","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":370,"y":160,"wires":[[]]},{"id":"b369c52d22fe8e01","type":"subflow:f59e3fa306dac4d1","z":"10aa4c3ab6ad18a1","name":"","x":530,"y":380,"wires":[[]]}]

```

---

<div class="post-metadata">

**Author:** ![oliver](https://avatars.discourse-cdn.com/v4/letter/o/85f322/32.png) [@oliver](https://discourse.nodered.org/u/oliver)\
**Post date:** [20 February 2022 19:23 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/9 "2022-02-20T19:23:46Z")

</div>

One file read node has it's output property set to string and the other file read node has it's output property set to buffer. If I not modify the output property the image is not send correctly by the http response node.

---

<div class="post-metadata">

**Author:** ![oliver](https://avatars.discourse-cdn.com/v4/letter/o/85f322/32.png) [@oliver](https://discourse.nodered.org/u/oliver)\
**Post date:** [20 February 2022 19:27 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/10 "2022-02-20T19:27:54Z")

</div>

Yes that looks good and covers all! Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 April 2022 19:28 UTC](https://discourse.nodered.org/t/how-to-set-the-output-property-of-the-file-read-node-with-a-function-node/58686/11 "2022-04-21T19:28:46Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
