title: Send text as a download file
body: <p>Trying to send simple text string as a file, that being downloaded under certain name upon request. Can't seems to figure out why this code fails.</p>
  
  <pre><code>var text_ready = "This is a content of a txt file."
  res.setHeader('Content-type', "application/octet-stream");
  res.setHeader('Content-disposition', 'attachment; filename=file.txt');
  res.send( new Buffer(text_ready) );
  </code></pre>
  
  <p>When this code executes, I receive only a XHR response (with that string as a content), but no download is being initiated. But I expected that receiveing this response will force browser to download a file with <code>file.txt</code> as a name having content of the string above.</p>
  
  <p>How to fix that? What am I doing wrong?</p>
  
  <p>Maybe it will be important: working under Chrome 41 on Windows.</p>
  
  <p><strong>EDIT:</strong> it seems that I have to describe a bit deeper. The workflow is the following:</p>
  
  <ul>
  <li>page contains a table cells with angular <code>ng-click</code> events attached to each of them</li>
  <li>when clicking a GET request is being sent to "/download" using jQuery's $.get("/download")</li>
  <li>server have route to handle this GET requests</li>
  <li>what I need to achieve is that a certain text string is being send to user and saved as a file (so that a download is being initiated upon click, shortly speaking)</li>
  </ul>
  
  <h3>testings</h3>
  
  <ol>
  <li>It <strong>works</strong> when I <strong>navigate</strong> manually to that url by entering this url to address bar and pressing enter</li>
  <li>It <strong>does not work</strong> when I <strong>click with mouse</strong> on that cell - the request is sent, the response is received but no download is initiated.</li>
  </ol>