title: Dynamically creating a file with node.js and make it available for download
body: <p>I am building a text editor in Node.js where a user create a file in a textarea. When he is done editing the file, he can push an "export" button that triggers a Jquery function that reads the textarea and post the text on the node.js server. The server should read the information and return a file. I would like to avoid creating a file on the server and servicing it, I'd rather create a file on the fly with streams. I have tried using the following and but that didn't work:</p>
  
  <pre><code>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)
  }
  </code></pre>
  
  <p>Does anybody have any insight on how to achieve this?</p>