Reputation: 394
I am following node.js tutorials on learnyounode, the "HTTP CLIENT" section. The code that is proposed as solution is:
var http = require('http')
http.get(process.argv[2], function (response) {
response.setEncoding('utf8')
response.on('data', console.log)
response.on('error', console.error)
})
but executing this with node gives me
events.js:72
throw er; // Unhandled 'error' event
my working solution is this one:
var http = require('http')
http.get(process.argv[2], function (response) {
response.setEncoding('utf8');
response.on('data', console.log);
}).on('error', console.error);
that means that the Object response is not a http.ClientRequest ?
Upvotes: 1
Views: 110
Reputation: 410
Yep, response is http.ServerResponse while request is http.ClientRequest. As the docs say, error
event is emitted on request object, not response one.
Upvotes: 1