I would like to know where in the official docs of nodejs, the Event data
and Event close
of a response
are explained. I want to find out where these events are explained so I can learn what other events are available to be used.
I was checking these official docs here but I could not find any explanation and could not find what are other event are available to be fired on response
object
my code:
var options = {
protocol:'https:',
host: constants.END_POINT_HOST_JK,
path: constants.END_POINT_PATH_JK,
method:'GET',
headers: {
'Content-Type': 'application/json'
}
};
var callback = (response)=>{
if (response.statusCode !== 200) {
console.error("Did not get an OK from the server. Code:",response.statusCode);
console.error("Did not get an OK from the server. Msg:",response.statusMessage);
res.resume();
return;
}
var data = '';
response.on('data', (chunk)=>{
data += chunk;
});
response.on('close', ()=>{
console.log('Retrieved all data');
console.log(JSON.parse(data));
});
}
var req=https.request(options, callback);
req.on('error', (e) => {
console.error("problem with request:", e);
});
req.end();
2
Answers
Here is the link directly to the page you asked for:
https://nodejs.org/api/events.html#eventsonemitter-eventname-options
*how to get to it
So in the node docs, scroll down on the left menu, until you get to events:
https://nodejs.org/api/events.html and then there is
events.on()
in there.Your link was to the
http
section of the nodejs docs. Try using the left menu thing to access different aspects of node.You are starting at the right place.
Scroll down to http.IncomingMessage
See that it Extends: stream.Readable
Click that.
The events you are asking about aren’t unique to HTTP responses, so they are inherited from the parent class and the documentation is linked not duplicated.