If I run it in the command line, the program will stop after client.destroy();
var client = http.get(options,
function(res) {
console.log(res.statusCode);
client.destroy();
}
);
However, it is not the case when I put the client.destroy() inside the res.on('end'):
var client = http.get(options,
function(res) {
console.log(res.statusCode);
res.on('end', function() {
console.log("done");
client.destroy();
});
}
);
It will throw exception because the http.socket is null. so, I can't destroy it.
IN this case, the program execution will hang there and will not end. What can I do to stop it? (other than process.exit());