0

I really can't figure out what I've done wrong. I've spent about half an hour looking at this code and re-reading code that essentially does the same thing and works. The 'data' event and corresponding callback is never triggered.

var http = require("http");

http.createServer(function(request, response){
    response.writeHead(200);
    console.log('Executing');

    request.on('data', function(chunk){
        console.log('data being read');
        console.log(chunk.toString());
     });

    request.on('end', function(){
         console.log('done');
         response.end();
    });
}).listen(8080);

Please help

k29
  • 641
  • 6
  • 26
  • Can you provide details of an example request that you're trying? And, note that `GET` and `HEAD` requests [don't generally include a body](http://stackoverflow.com/q/978061), so `'data'` may not be sent with them. – Jonathan Lonowski Sep 15 '13 at 14:44
  • @w00d node server.js @"Jonathan Lonowski" I just direct a webbrowser to IPofmyserver:8080 – k29 Sep 15 '13 at 14:51

1 Answers1

1

You probably aren't sending a request body, so the data and end event don't fire. Trying sending a POST or PUT request. If you use a GET request with a query string, you will fire the end event, but not data.

hexacyanide
  • 88,222
  • 31
  • 159
  • 162