Well, obviously, you are trying to send something that is not a string or a buffer. :) It works with the console because the console accepts anything. A simple example:
var obj = { test : "test" }; console.log( obj );
One way to convert something to a string is:
res.write( "" + obj );
whenever you try to send something. Another way is to call the .toString() method:
res.write( obj.toString( ) );
Please note that this may still not be what you are looking for. You should always pass strings / buffers to .write without such tricks.
As a side note: I assume that request is an asynchronous operation. If this happens, then res.end(); will be called before any entry, i.e. Any record will fail anyway (because the connection will be closed at this point). Move this line to the handler:
request({ uri: 'http://www.google.com', method: 'GET', maxRedirects:3 }, function(error, response, body) { if (!error) { res.write(response.statusCode); } else {
freakish Feb 12 '13 at 15:20 2013-02-12 15:20
source share