title: Express : Shouldn't middleware stop being called once a response is made?
body: <p>I have this issue where <strong>inside a router file that returns a router object - middleware is getting called after a response is already made.</strong></p>
  
  <p>I thought middleware placed after a route will never get executed
  for that route, I especially thought that would be true if a response
  was already given.</p>
  
  <p><strong>Main question:</strong> </p>
  
  <p><strong>Middleware should stop being called after the response right?</strong></p>
  
  <p>Ex: When calling the endpoint "/login" and sending a response
      both middleware A and B are called.</p>
  
  <p>Note: I have wrapped the router in a higher order function
  (for socket.io functionality but that is beside the point). </p>
  
  <p>Code Example:</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  var wrappedRouter = function(val) {
  
      router.get('/login', function(req, res) {
          console.log("Inside login route");
          res.sendFile(path.resolve('login.html'))
      }
  
      router.use(function(req, res, next) {
          console.log("Exectuing middleware A");
      });
  
      router.use(function(req, res, next) {
          console.log("Exectuing middleware B");
      });
  
      router.get('/another-route', function(req, res) {
          res.sendFile(path.resolve('login.html'))
      }
  
      return router;
  
  }
  //Prints:
  // Inside login route
  // Exectuing middleware A
  // Exectuing middleware B
  </code></pre>