title: nodeJS prevent timeout on res.download
body: <p>I have a POST call to my nodeJS server that searches for some data on the mongo database and returns a CSV file with the requested data. The problem is that the data search and processing exceeds the 2 minute nodeJS default timeout. </p>
  
  <p>On a diferent scenario y used: </p>
  
  <pre><code>res.writeHeader(200,'application/json');            
  res.write('starting fetch .... ');
  </code></pre>
  
  <p>to keep alive the request and prevent the timeout from the client by sending some <code>res.write('');</code> from time to time.</p>
  
  <p>Now Im using <code>res.download()</code> to download the resulting csv file, so not just sending JSON as response. </p>
  
  <p>Tried to use this solution like this: </p>
  
  <pre><code>res.writeHeader(200,'application/json');            
  res.write('starting fetch .... ');
  res.download()
  </code></pre>
  
  <p>But i get the "headers already sent" error.</p>
  
  <p>Any idea on how to prevent the timeout until the data is processed and the file download is done ? </p>
  
  <p>Thanks in advance</p>