Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How does express know to go to the error.pug page when using 'return next(err)'

The question says it all. Maybe I'm missing something here. Any help would be appreciated.

1 Answer

If you call next() function and pass an argument e.g next(arg), Express by default knows it should call the error handler function(middleware) . This is contrary to when you call the next () without passing any argument .It is the presence of argument that determines that the error handler should be called which renders the error page.Regards,

While your answer really did not go into depth, it still pointed me in the right direction and I appreciate that.
Thank you.