Welcome to the Treehouse Community
Looking to learn something new?
Why only the app.get and app.post methods put into the routes folder?
Is there any reason why you wouldn't put the error handlers in the routes folder? In general, do you never put the app.use() routes into the routes folder, and leave it in the app.js?
nico dev20,364 Points
I think that the routes folder is intended to modularize (is that even a word? |o| ) the routing stuff away from the actual app code, like the middleware you handle with
That makes a lot of sense, especially if you have to debug it.
The default handlers remain in the main file because they apply to the entire application (not specific to any component) and they need to be ordered last, after all other routes.
The handler generating a 404 error prevents handlers on laters routes from getting evaluated.
Try it out: move the handlers to
routes/index.js and observe requests to
/cards (whose handlers are set later) fail.