I create a text editor in Node.js where the user creates a file in a text box. When he finishes editing the file, he can click the βexportβ button, which launches the jQuery function, which reads the text field and publishes the text on the Node.js server. The server should read the information and return the file. I would like not to create a file on the server and serve it, I would rather create a file on the fly with streams. I tried using the following, but this did not work:
exports.exportfile = function(req,res){ var Stream = require('stream') var stream = new Stream(); res.setHeader('Content-disposition', 'attachment; filename=try.txt'); res.setHeader('Content-type', 'text/plain'); stream.pipe = function(dest) { dest.write('Hello Dolly') } stream.pipe(res) }
Does anyone have an idea on how to achieve this?
source share