title: Download file in NodeJS
body: <p>I am writing HTML WYSIWYG application. After a user edits a web page, they should be able to click a download button, and be prompted by their browser to save their edited web page. I do not want to store their edited web page on my server, but send the file to their local machine.</p>
  
  <p>So far in my application, I am able to edit a template, grab its HTML when the user clicks the download button, and using NodeJS's <strong>fs.createWriteStream</strong>  method, write the HTML to a newly created HTML file. However, it creates the file on my server instead of prompting the browser to save the file in a Downloads folder. I am using Socket.io to tell the server to download the HTML content.</p>
  
  <p>After research, I figured out that in order to make the browser prompt the user to save a download file, the HTTP headers must be set using the <strong>Content-Disposition: attachment</strong> header.</p>
  
  <p>In Summary, when the user clicks the download button in my application, what should I do so that a new file is created and saved directly on the users local computer instead of on my server?</p>
  
  <p>This is what I have in my server.js file:</p>
  
  <pre><code>io.sockets.on('connection', function(socket) {
      socket.on('downloadHTML', function(data) {
          var file = fs.createWriteStream('PearlEdit-template-Martketing.html', {flags: 'w'})
                  .write(data.html);
      });
  
  });
  </code></pre>