title: Express.js Response Sent Callback
body: <p>I have the following code in Node/Express that sends a file as a response then deletes the file using a timeout.</p>
  
  <pre><code>res.sendFile(req.params.id, { root: process.env.UPLOADPATH });
  
  setTimeout(function () {
      if (fs.existsSync(process.env.UPLOADPATH + req.params.id)) { // check to ensure file still exists on file system
          fs.unlink(process.env.UPLOADPATH + req.params.id); // delete file from server file system after 60 seconds
      }
  }, 60000);
  </code></pre>
  
  <p>If I didn't use the <code>setTimeout</code> it failed with an error. I'm assuming Express does the <code>sendFile</code> async so it was deleting the file before it actually sent.</p>
  
  <p>Is there a better way to do this tho? Is there a way to check for when the file has been sent so I can safely delete it? Maybe like a <code>sendFile</code> callback or something?</p>