How to serve string from memory as a file?

Hi,

I've followed examples which allow me to serve a file from node red dashboard/ui. What I would like to do is to just serve the file as a string direct from memory. Please can someone point me to an example, or explain why I shouldn't do this? I'm only talking about small to medium log files.

Thanks.

I don't fully understand what you are trying to do. Do you mean that you have a string in, for example, msg.payload and you want to show it on the dashboard? If so, just send it to a ui-text node.

Or if you mean that you want to send it to a file then use a file out node to do that.

Where does the string live? In Node-RED or in dashboard?

If it is in Node-RED, you can setup an endpoint (http-in --> change node (put the string in payload) --> http-response) (see endpoint examples in the Node-RED cookbook in the docs).

To make it a file, set the appropriate headers in the http-response node such that it has a file and content disposition

You can even do it dynamically in a function node

const logContent = "2026-07-20 INFO: System operational\n2026-07-20 ERROR: Connection failed" // or from context or wherever your log string is
const byteLength = Buffer.byteLength(logContent, 'utf-8');
const filename = 'system.log' // or dynamic like formated-time.log
msg.headers = {}
msg.headers['Content-Disposition'] = `attachment; filename="${filename}"`
msg.headers['Content-Type'] = 'application/octet-stream'
msg.headers['Content-Length'] = byteLength 
return msg

This would be passed to the http-response node

Then in your dashboard, you can use a simple anhor (hyperlink) that points to the endpoint

@Colin Evening. Thanks for your reply. I wanted a user to be able to download some log data from the UI/webpage that is stored as a string in node-red. I have a working example already but it works by requesting a file from the system which it then downloaded by the user's browser.

I wasn't too comfortable about this as it requests from the file system which feels like a potential vunrability and I'm having to dump to file before that file is then read and sent over the network. Seemed counter productive.

Looks like the other poster may have a workable solution.

@Steve-Mcl Evening. Thanks for your reply. That looks like what I am after, I will take aclose look at that.

@Steve-Mcl Thanks that worked great.