1

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 ?

1 Answer 1

1

Yep, response is http.ServerResponse while request is http.ClientRequest. As the docs say, error event is emitted on request object, not response one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.