From the course: Node.js: Debugging and Performance Tuning

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Implementing Express error pages

Implementing Express error pages

From the course: Node.js: Debugging and Performance Tuning

Start my 1-month free trial

Implementing Express error pages

- [Instructor] We're going to use Express' built-in middleware to implement some error pages that log to the console. Then we'll fix that first issue. Why bother to implement error pages? It's a best practice to implement custom error pages in node applications for a couple of reasons. First, there's the control over the user experience. It can be very jarring to get a white page with a little bit of diagnostic information instead of a nicely themed error page. Also, in the case of 404s, some sites have a custom call-to-action that can direct users to actual content destinations. Finally, custom error pages give an opportunity to implement logging that is contextually appropriate. For example, you may not want to log a stack trace if someone goes to a non-existent link in your application. Let's start with a 404 handler first and we'll log a warning when it happens along with the details about the failure. Switch over to your editor. I'm gonna close the terminals, so we can see more…

Contents