# Packaging Files in a Node-Red Flow

**URL:** <https://discourse.nodered.org/t/packaging-files-in-a-node-red-flow/31727>\
**Category:** Developing Nodes\
**Created:** [19 August 2020 13:02 UTC](https://discourse.nodered.org/t/packaging-files-in-a-node-red-flow/31727 "2020-08-19T13:02:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jennyeg](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jennyeg](https://discourse.nodered.org/u/jennyeg)\
**Post date:** [19 August 2020 13:02 UTC](https://discourse.nodered.org/t/packaging-files-in-a-node-red-flow/31727/1 "2020-08-19T13:02:20Z")

</div>

Hello everyone,

I have created a flow that I would like to publish, however my flow relies on reading a html file and a javascript file. My file node is currently reading these files from my local machine. However, when I publish this node, I would like for others to be able to access these files. Is there a way that I can package these files into the flow?

Thanks!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 August 2020 14:46 UTC](https://discourse.nodered.org/t/packaging-files-in-a-node-red-flow/31727/2 "2020-08-19T14:46:09Z")

</div>

Hi Jenny,

How much data are we talking about? (how big are these files) and what type of data are in these files?

You could include the file contents in a change node or template node & then instead of using the `file in` node, simply go via the change or template node.

---

<div class="post-metadata">

**Author:** ![jennyeg](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jennyeg](https://discourse.nodered.org/u/jennyeg)\
**Post date:** [19 August 2020 15:03 UTC](https://discourse.nodered.org/t/packaging-files-in-a-node-red-flow/31727/3 "2020-08-19T15:03:47Z")

</div>

Steve,

My html file is 25 KB and my javascript file is 5KB. These files make a series of http requests to an API server and return JSON data. Is it possible to insert html/ javascript code in the change node or template node? How would this be done?

Thanks!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 August 2020 15:26 UTC](https://discourse.nodered.org/t/packaging-files-in-a-node-red-flow/31727/4 "2020-08-19T15:26:46Z")

</div>

Well as an example, on a project I maintain, I store HTML (with embedded `<script>`) in a template node (here you can see a dev and live version) and when an external application calls the end point (`[get]`), they get the html passed from the dev or live template to the end point

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/c/1c310fe7af54a0ab12a36b3bcaefb65511a86127.png)

the http response node has following header set so that it is treat as HTML...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/05a27e89c41fd332bae97f63e5e5d56fbd516055.png)

NOTE: the html in the dev and live templates are about 26kb - seems to run very well - its been running about 6 months with about 100 individual users consuming it

---

<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:** [19 August 2020 15:55 UTC](https://discourse.nodered.org/t/packaging-files-in-a-node-red-flow/31727/5 "2020-08-19T15:55:42Z")

</div>

I think I am right in saying that any files you include in the node's directory structure will be included in the package, and will therefore be in the node's install folder, but I don't know how you would access them from there at run time, or if that is even possible.

---

<div class="post-metadata">

**Author:** ![jennyeg](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jennyeg](https://discourse.nodered.org/u/jennyeg)\
**Post date:** [19 August 2020 17:37 UTC](https://discourse.nodered.org/t/packaging-files-in-a-node-red-flow/31727/6 "2020-08-19T17:37:10Z")

</div>

@Steve-Mcl I tried your example and was able to get this to work successfully for my html file. However, I have not been able to do this with my javascript file. I tried setting the content-type for this file to text/javascript but this is still not working. I also tried setting a script inside of an html element for the javascript file but I have still not been successful. I also have two images embedded within my html file that I'd like to add. I tried adding these into my node-red flow project in a folder, but was not successful. Do you know if there is a way to embed an image in a template node. Thank you for your help!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 August 2020 17:44 UTC](https://discourse.nodered.org/t/packaging-files-in-a-node-red-flow/31727/7 "2020-08-19T17:44:44Z")

</div>

> [@jennyeg](#):
>
> I also have two images embedded within my html file that I'd like to add

There are a couple of ways...  
1-  
You can convert an image to base64 then set the `img` src as the base64 data - that embeds the image.  
e.g. [Tutorial - Base64 Image Encoder](https://www.base64-image.de/tutorial)

2-  
You can convert an image to base64 then store the base64 string separately in a template and return it to the user as another endpoint like you are doing with the HTML string. (you would also set the content type accordingly)

NOTE1: You would be **very** wise to reduce the images to the smallest possible size before conversion to base64 as the string data can be very large (easily much larger than the html+js combined).

NOTE2: This is not the idea way of achieving this sort of thing - you'd be better off hosting the files and the having a `public` folder. Alternatively you could zip the files and tell the user how to do this?

---

<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:** [18 October 2020 17:44 UTC](https://discourse.nodered.org/t/packaging-files-in-a-node-red-flow/31727/8 "2020-10-18T17:44:48Z")

</div>

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