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 Build a REST API With Express Building API Routes in Express Error Handling in Express

calling next()

I am wondering why in app.use("/questions", routes); we do not have to call next().... Thanks!

Steve Gardner
Steve Gardner
17,786 Points

This method is simply sending the request to our routing file. You can call next() from within the routes for many different reasons such as setting params, using multiple callbacks, or error handling.

1 Answer

To my understanding, when you call 'routes', it's calling all of the routes.js page, with all of it's routes, under the "/questions" path.

Also, those are not the same as separate middleware instances. They are all routes, waiting to be called, not all being called sequentially as middleware calls would be. I believe.

I hope that helps.