title: How do you programmatically exit a node.js/express route on an event?
body: <p>I want to be able to exit execution of a post route when an event is sent from the client-side. I'm using socket.io but I'm not sure it can do what I want. I am using the <code>uploads</code> route to process a file, but if the user deletes the file, I want the <code>app.post</code> execution to end, similar to either a <code>res.end()</code> or <code>return</code> statement.</p>
  <p>My app in the front-end receives a file from the user and immediately is sent to the post route for processing. If the user deletes the file and uploads a new one, the previous post route is still going. I want to make sure the previous one was terminated, cancelled, etc.</p>
  <p>I'm currently using socket.io to communicate front-end to back-end.</p>
  <p>How can I achieve this?</p>
  <pre><code>app.post('/uploads', async (req, res) =&gt; {
      // async func1
  
      // async func2
      // if we receive an event from the front end while processing here, how can I exit the post route?
  
      // async func3
  });
  </code></pre>