Found this code to debug this problem where the following did not work:
var req = http.request(options,function(res){ // res.on('error',cb(err)); res.on('end',function(){ cb(); }); });
However, the following worked:
var req = http.request(options,function(res){ // res.on('error',cb(err)); res.on('data',function(chunk){ //why do we need this? }); res.on('end',function(){ cb(); }); });
The variable resis a Readable Stream . If you click the link and scroll down to the 'end' event , you can find the following:
res
Please note that the event "end" will not occur if the data is not completely destroyed.
Adding an event handler "data", you will use the data.
node. , ( TCP). , ( res.read() data res.resume()), , . , , end. res.resume();, .
res.read()
data
res.resume()
end
res.resume();
node v0.10. , data, , . , node v0.10 + - , ( node, ).
function(res) - , 'data' 'end', .
function(res)
'data'
'end'
:
"" ; "".'response' , . , "response", response.read() , "" , .resume(). , "" . , , , " ".
"" ; "".
'response' , . , "response", response.read() , "" , .resume(). , "" . , , , " ".