I think the error is probably not in your requestHandlers.js. Although, in your snippet you've forgot to put in the "response.write("You've sent the text: " + stuff);" line, I'm assuming this is a copy and paste error.
Your start.js file should look like this:
var http = require("http");
var url = require("url");
function start(route, handle) {
function onRequest(request, response) {
var postData = "";
var pathname = url.parse(request.url).pathname;
console.log("Request for " + pathname + " received.");
request.setEncoding("utf8");
request.addListener("data", function (postDataChunk) {
postData += postDataChunk;
console.log("Received POST data chunk '" + postDataChunk + "'.");
});
request.addListener("end", function () {
route(handle, pathname, response, postData);
});
}
http.createServer(onRequest).listen(8888);
console.log("Server has started");
}
exports.start = start;
Note that the route is called in the request objects "end" handler and the postData is built up in "chunks" in the request object's "data" handler.
In your router.js file should be;
function route(handle, pathname, response, postData) {
console.log("About to route a request for " + pathname);
if (typeof handle[pathname] === 'function') {
handle[pathname](response, postData);
} else {
console.log("No request handler found for " + pathname);
response.writeHead(404, {
"Content-Type" : "text/plain"
});
response.write("404 Not found");
response.end();
}
}
exports.route = route;
I suppose the key here is to make sure you are passing the postData variable and NOT the request variable. I'm guessing this is what is happening in your code.
This is all on pages 51-53 of the book.