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.


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.


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.


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.


Yes it’s still not fixed. Please can the put function be added to the starter code (or deleted from the solution)

For people still struggling, insert the below code into yours around line ~122 - after the app.delete() and before app.listen()

app.put('/beans/:beanName/name', (req, res, next) => {
  const beanName = req.params.beanName;
  if (!jellybeanBag[beanName]) {
    return res.status(404).send('Bean with that name does not exist');
  let queryData = '';
  req.on('data', (data) => {
    queryData += data;

  req.on('end', () => {
    const newName = JSON.parse(queryData).name;
    jellybeanBag[newName] = jellybeanBag[beanName];
    jellybeanBag[beanName] = null;
    console.log('Response Sent');

I’m finding the back-end course so far really lazily put together. This bug was so annoying and in general I just feel as though the back-end course is not as well explained as the front-end course was. Having to do so much extra research just to understand what the heck I’m being asked to do and why. Not ideal at all and as I say it was not this way on the front-end course at all :sob: