title: How to make Node.js wait for response from a large request
body: <p>I am posting a large number of files that can take potentially minutes to upload. I using a multi-part form to post the files and then waiting for a response from the POST, but this can take several minutes.</p>
  
  <p>How do I make Node/Express wait for this response? As of now, it seems like the request is "timing out" and Node or the browser is re-POSTing the files because it is taking so long. I can see this because my middleware functions are being called multiple times for requests that take too long.</p>
  
  <p>Is there a library to make Node not timeout? Should I be attempting to POST these files in a different fashion? Thanks</p>
  
  <pre><code>var mid = function(req,res,next) {
    console.log('Called');
    next();
  };
  
  app.post('/api/GROBID', mid, authenticate, PDFupload.return_GROBID, PDFupload.post_doc, function(req, res) {
    if (res.locals.body == 400) res.send(400);
    /*if (process.env.TEST_ENV == 'unit-testing') {
      res.send(res.locals.body);
    }*/
    res.render('uploads', {files : res.locals.body});
  });
  </code></pre>
  
  <p>Edit: This mid middleware (used as an example) is being called twice. This means the route is being posted to twice. How do I make sure this does not happen?</p>