title: Node.js request data event not firing. What am I doing wrong?
body: <p>It seems like the data event on the request object is not firing, or I can't wire it up right in order to get anything from it. I am getting the end event just fine, and all the urls are working. I have looked on forums and documentation, and when I look at my code it seems like it should work. I am using Node version 0.10.12.</p>
  
  <p>I am new. I am trying to get a simple server going in node. I was following The Node Beginner Book. Most of this code comes from there, with some very small modifications. I have already tried the code straight from the book.</p>
  
  <p>Here is the code I am working with now.</p>
  
  <p>index.js</p>
  
  <pre><code>var server = require("./server");
  var router = require("./router");
  var requestHandlers = require("./requestHandlers");
  
  var handle = {};
  
  handle["/"] = requestHandlers.start;
  handle["/start"] = requestHandlers.start;
  handle["/upload"] = requestHandlers.upload;
  
  if (process.argv[2] !== undefined &amp;&amp; process.argv[2] !== null) {
      server.start(router.route, handle, process.argv[2]);
  } else {
      server.start(router.route, handle);
  }
  </code></pre>
  
  <p>router.js</p>
  
  <pre><code>route = function(handle, pathname, response, postData) {
      if (typeof handle[pathname] === "function") {
          handle[pathname](response, postData);
      } else {
          response.writeHead(404, {"Content-Type": "text/plain"});
          response.end("404 Not found");
      }
  }
  
  exports.route = route;
  </code></pre>
  
  <p>server.js</p>
  
  <pre><code>var http = require('http');
  var url = require('url');
  
  var portToUse = 8888;
  
  start = function(route, handle, port) {
      if (port !== undefined &amp;&amp; port !== null &amp;&amp; typeof parseInt(port) === 'number' &amp;&amp; port &gt; 1000 &amp;&amp; port &lt; 10000) {
          console.log('You passed in the port number %d.', port);
          portToUse = port;
      }
  
      http.createServer(function(request, response) {
          var postData = '';
          var pathname = url.parse(request.url).pathname;
          console.log('Request for %s received.', pathname);
  
          route(handle, pathname, response);
  
          request.setEncoding('utf8');
  
          // I have tried both .on and .addListener
          request.on('data', function(postDataChunk) {
              postData += postDataChunk;
              console.log('Received POST data chunk %s.', postData);
          });
  
          request.on('end', function(postDataChunk) {
              console.log(postDataChunk);
              route(handle, pathname, response, postData);
          });
      }).listen(portToUse);
  
      console.log('The server listening on %d.', portToUse);
  }
  
  exports.start = start;
  </code></pre>
  
  <p>requestHandlers.js</p>
  
  <pre><code>var exec = require('child_process').exec;
  
  start = function(response, postData) {
      var body = '&lt;!doctype html&gt;' + 
      '&lt;html lang="en"&gt;' + 
      '&lt;head&gt;' + 
      '&lt;meta charset="UTF-8"&gt;' + 
      '&lt;title&gt;Upload Server&lt;/title&gt;' + 
      '&lt;/head&gt;' + 
      '&lt;body&gt;' + 
      '&lt;form action="/upload"&gt;' + 
      '&lt;textarea name="text" id="text-area" cols="40" rows="20"&gt;&lt;/textarea&gt;' + 
      '&lt;input type="submit" value="Submit text"&gt;' + 
      '&lt;/form&gt;' + 
      '&lt;/body&gt;' + 
      '&lt;/html&gt;';
  
      response.writeHead(200, {"Content-Type": "text/html"});
      response.end(body);
  }
  
  upload = function(response, postData) {
      response.writeHead(200, {'Content-Type': 'text/plain'});
      response.end('You\'ve sent: ' + postData);
  }
  
  exports.start = start;
  exports.upload = upload;
  </code></pre>
  
  <p>Thanks in advance.</p>