Error handling in Node

Can someone explain how to properly handle errors in Node because the tutorial makes no effort to.

var http = require("http");
var bl = require("bl");
var url =process.argv[2]; // 1st command line argument

http.get(url, function(err, response) {
    response.pipe(bl(function (data) {
        console.log(data);
    }));
    response.on("error", function(err) {
        throw new Error("Doh!!!");
    });
}).on('error', function(err) {
    throw new Error("Doh!!!");
});

Heading for the solution now. Is this the best way to learn I wonder :confused: ?

No, its not I struggled with how-to-node too. If you want to really understand what you are doing take a look at this course, I have been taking it and its making things a lot clearer.
https://www.udemy.com/understand-nodejs

1 Like

Thanks for that @P1xt & @IsaacAbrahamson . I am currently going through the linked in / learning course. That’s 6 hrs long and very good so far.
Also, I have Pair programmed with someone today and completed the learnyounode course.
What helped today was looking at NodeJS API

I think getting familiar with the many modules will help. I will watch those before moving to the next challenge. Cheers. :beers:

1 Like