title: Socket.IO middleware, io.use
body: <p>Working on a web application which is built upon expressJS and Socket.io.
  In <a href="https://stackoverflow.com/questions/36788831/authenticating-socket-io-connections">the following post</a> I saw the usage of middleware syntax which was new to me. Here is an example of the syntax:</p>
  
  <pre><code>const io = require('socket.io')();
  
  io.use(function(socket, next) {
    // execute some code
    next();
  })
  .on('connection', function(socket) {
      // Connection now authenticated to receive further events
  
      socket.on('message', function(message) {
          io.emit('message', message);
      });
  });
  </code></pre>
  
  <p>It basically uses middleware functions on the <code>socket.io</code> instance. My previous understanding was that middlware can only be used on the express instance (<code>app.use(...)</code>).</p>
  
  <h2>Questions:</h2>
  
  <ol>
  <li>Is this syntax just regular middleware which works similarly to <code>app.use(...)</code>?</li>
  <li>If it is different, what are the differences?</li>
  </ol>