title: Express4 error middleware sequence
body: <p>Came accros a sequence of code execution which I found unusual here is the code:</p>
  
  <p><strong>server.js</strong></p>
  
  <pre><code>const Actions_Single_PVC = require('./routes/Actions_single_PVC.js');
  
  app.use('/Actions_single_PVC', Actions_Single_PVC);
  
  app.use((err, req, res, next) =&gt; {
  
      console.log('invalid token');
  
  });
  </code></pre>
  
  <p><strong>Actions_single_PVC.js</strong></p>
  
  <pre><code>router.post('/', asyncMW(async (req, res, next) =&gt; {
  
  throw new Error();
  
  }));
  
  router.use((err, req, res, next) =&gt; {
    console.log('error');
  }
  </code></pre>
  
  <p>And in case you have never seen this construction before here is asyncMW:</p>
  
  <pre><code>const asyncMiddleware = fn =&gt;
    (req, res, next) =&gt; {
      Promise.resolve(fn(req, res, next))
        .catch(next);
    };
  
    module.exports = asyncMiddleware;
  </code></pre>
  
  <p>What I didn't understand was that when an error is thrown (I reproduced it here with <code>throw new Error();</code>) that the error handling middleware in the  <code>server.js</code> file is executed. I expected that the error handling middleware of the  <code>Actions_single_PVC.js</code> would get executed.</p>
  
  <h2>Question:</h2>
  
  <p>Why is the error middlware in <code>server.js</code> executed and not the error middlware in <code>Actions_single_PVC.js</code>?</p>