This course has been updated! We now recommend you take the Introduction to Node.js, v3 course.

Check out a free preview of the full Introduction to Node.js course:
The "Error Handling" Lesson is part of the full, Introduction to Node.js course featured in this preview video. Here's what you'd learn in this lesson:

Scott explains why it's imperative to handle errors in Node js.

Get Unlimited Access Now

Transcript from the "Error Handling" Lesson

>> Speaker 1: Now we're going to talk about error handling a little bit. So we talked about handling those errors. But now we're gonna talk about why you need to handle those errors. Any thrown or unhandled error will cause the process to crash and exit. That's fine in a browser, maybe.

[00:00:14] But on the server, if you have one server serving a million requests, and one error crashed the entire server. Nobody can use your product. So it's not really a good thing. So you need to handle those errors and especially think about the unhandled ones and stuff like that.

[00:00:28] Your app may have errors that should not cause a crash. So you must handle them accordingly. Like if I have an API and a user is trying to authenticate but that user, they sent up invalid authentication token, and that causes an error on my server. That shouldn't crash my server because a user sent me an invalid authentication token.

[00:00:48] I should just send back a proper response. I should handle that and send it back. Just because there was an error, that doesn't mean my app should crash. I should accordingly figure out this should definitely cause a crash, or, this was a user error. Just let them know about it, and things like that.

[00:01:01] So every error shouldn't cause your app to crash. Some you just don't care about, some you do. So you gotta figure out accordingly how that works.