title: Combine sockets and express when using express middleware?
body: <p>Is there a way to get the socket of a request inside of an express middleware?</p>
  
  <p>ie:</p>
  
  <pre><code>import express from 'express';
  import io from 'socket.io';
  
  const app = express();
  
  // combine app and io somehow ...
  
  // When client makes a GET request to '/emit/to/self', that client's socket will recieve the 'hello:world' message.
  app.get('/emit/to/self', (req, res) =&gt; {
    req.socket.emit('hello:world', { ... });
    res.send('You just triggered your own socket!')
  })
  </code></pre>
  
  <p>The idea being that express middleware has a <code>req.socket</code> property that references the connected socket from the same client. This would allow for some more complex use cases, such as:</p>
  
  <pre><code>app.post('/image/create', (req, res) =&gt; {
    createExpensiveImage({
      onProgress: (progress) =&gt; { req.socket.emit('image:progress', { progress }) },
    });
  })
  </code></pre>
  
  <p>The client would have an accurate progress bar of the image they just requested to create through the API.</p>