title: Extracting Post Data using the Express Router
body: <p>My question is why request events fire when I DO NOT use the Express Router, but when I do use it, my request.on('data', ...) and request.on('end', ...) events don't fire.  I am guessing it has something to do with callbacks but it could also be me making a mistake.</p>
  
  <p>I have a 'form' with the following:</p>
  
  <pre><code>&lt;form method="post" action="/"&gt;
    &lt;input type="text" name="user[name]"&gt;
    &lt;input type="text" name="user[email]"&gt;
    &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>IF</strong> I put the following in my app.js file, everything works properly</p>
  
  <pre><code>app.post('/', (req, res) =&gt; {
    var body = '';
  
    req.on('data', (data) =&gt; {
      body += data;
    });
  
    req.on('end', () =&gt; {
      var post = qs.parse(body);
      console.log(JSON.stringify(post)); 
      res.redirect('/');
    });
  });
  </code></pre>
  
  <p><strong>HOWEVER</strong> if I use the Router so my app.js has</p>
  
  <pre><code>var routes = require('./routes/index');
  app.use('/', routes);
  </code></pre>
  
  <p>and my index.js has</p>
  
  <pre><code>  router.post('/', (request, response) =&gt; {
    var body = '';
    console.log('in here');
  
    request.on('data', (chunk) =&gt; {
      body += chunk;
  
      if(body.length &gt; 10e6){
          request.connection.destroy();
      }
    });
  
    request.on("end", () =&gt; {
      var form = qs.parse(body);
      console.log(JSON.stringify(form));
      response.redirect('/');
    });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Then the 'data' and 'end' events are never called suggesting (to me at least) that router.post is a callback and the events have already been called.  </p>
  
  <p>Is my logic correct?  If so that is unfortunate as I can't use this method and must use body-parser.</p>