FAQ: Middleware - DRYing Code With Functions

This community-built FAQ covers the “DRYing Code With Functions” 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 Code With Functions

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!

What does the code req.on() do? I couldn’t find any documentation about the on method for a request. Please explain.

Method .on belongs to the class EventEmitter, here you can find documentation for this method -> https://nodejs.org/docs/latest/api/events.html#events_emitter_on_eventname_listener.

So the purpose of the .on method is to specify an event handler.

3 Likes

This section appears to be broken, I spent quite a lot of time trying to figure out what was wrong with my code, finally, I just copy and paste the solution code into the editor after resetting, it was still marked wrong.

2 Likes

Yes, I just had the same issue: cleaned all my code, was identical to solution. Still did not pass.

I then copy-pasted the entire solution, reset the workspace, copied their solution. Did not pass either.

Can Codecademy please fix this? It’s really not ideal.

2 Likes

This lesson is broken, i spent 30mn over a bug. Please fix for other learners! Had to use the solution code to pass, even though my code was 100% identical

1 Like

Stuck here too, literally copy pasted the solution but still errors out.

I’m having the same issue. Tried legitimately doing what it asked. Then trying copying the solution using both ‘replace with solution’ and a manual copy paste. Neither worked.

Is there a way to skip to the next page whilst this one is fixed? I’d like to avoid skipping the whole middle section just because of one little bug, but when I try to select the next page from the path menu it doesn’t let me.

The solution code for page 2/15 of this lesson has a app.put() function that doesn’t appear in the starting code. This is why the lesson is broken: it expects you to call the logRequest() function on the console.log call inside the app.put() function, that isn’t given to the user. Adding that function to the starting code (or copying it from the solution code, for anyone having trouble before it’s fixed) will solve the problem.