FAQ: Middleware - DRYing Routes With app.use()

This community-built FAQ covers the “DRYing Routes With app.use()” exercise from the lesson “Middleware”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn Express

FAQs on the exercise DRYing Routes With app.use()

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

why couldn’t you call logRequest(req.method) from inside the app.use?

const logRequest = (verb) => {
  console.log(`${verb} Request Received`);

app.use((req, res, next) => {

(the suggested solution is

app.use((req, res, next) => {
  console.log(`${req.method} Request Received`);

, which i get is more compact, but why would the option using logRequest not work at all?)

what is app.use()'s callback function? Is it the anonymous function, (req, res, next) => {};?

aren’t req, res, next callback functions? This is so confusing

Why does the previous lesson exist? Why did I do something wrong and labouriously insert a pointless function into the code only for this lesson to say “lmao that was wrong, here’s how to do it right”? The LAST THING you do with beginners learning a new skill is teach them how to do it wrong. You teach them to do it RIGHT, even if you don’t necessarily explain everything right away. This entire express.js section is full of this kind of contradictory, time-wasting nonsense. edit: also, why is the solution check case sensitive? It didn’t like my code until I capitalized the log string precisely the same way as the solution.