FAQ: Learn Express Routes - Using Queries

This community-built FAQ covers the “Using Queries” exercise from the lesson “Learn Express Routes”.

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

Web Development

Learn Express

FAQs on the exercise Using Queries

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!

Using Queries is a fraking wall. Before this part everything was relatively clear. But this. I just do not understand what is happening and even after hitting button “solution” I can’t deconstruc and understand how to get this result and what does it do at all. Very “interesting” way to teach people stuff.


I agree. I was lost here too.

I feel like the tutorial jumped (as in skipped some steps) and assumed we already knew how express worked.

I think if someone from codecademy performed a simple audit of this tutorial, they would agree… or not. I could just be dumb when it comes to Express.


I have to agree. The introduction of the new methods required (that become apparent when the solution is loaded) is missing in the lesson. The hints are not a lot of help and could perhaps be linked to an external resource.


The instructions are not clear in these lessons. The variables that are recommended and the logic that I am asked to perform are not clear or corollary. I feel frustrated that I have have the solution revealed just to understand what the instructions were directing me to do. There is some helpful information in here, but the Instructions need some more tweaking.

1 Like

My doubt here is I don’t find a way to make a request using any other verb different from get. I cannot find the ‘UPDATE’ tab. Can you tell me how can I activate / get it? Thanks.

Yeah, what happened here?

“You can use the updateElement helper function.”

What’s that?

1 Like

I’m still new here, so I hope my ‘noob-view’ will help others like me out. :slight_smile:

first off, notice this on line 7 in app.js
const { getElementById, getIndexById, updateElement,
seedElements, createElement } = require(’./utils’); // this is where you’re importing the ‘updateElement’ helper function

then break down the provided text into bite-size chunks.
Use req.query to update the proper element in the expressions array.
use the updateElement helper function.
It takes three arguments

  1. id (id number of element)
  2. queryArguments (new, updated expressions object from req.query)
  3. elementList (array which contains the element to update.)
    returns updated element
    Which means it will look like this:

updateElement(id, query, elementList)
//which, in the function we’re using, becomes:
updateElement(req.params.id, req.query, expressions)

Explaining the solution

app.put(’/expressions/:id’, (req, res, next) => { //whenever a PUT-request is sent to the server with the following path: '/expressions/:id, start the following function

const expressionIndex = getIndexById(req.params.id, expressions); //getIndexById takes the id as first parameter, filename as second. the index is now assigned to ‘expressionIndex’.
with this we can check, in the code below, if the requested id exists.

if (expressionIndex !== -1) { //if expressionIndex DOES NOT equal -1, it means an index has been found, proceed with next two lines of code
updateElement(req.params.id, req.query, expressions); //now update the element
res.send(expressions[expressionIndex]);//in server response, send back the updated element

} else {
res.status(404).send(); //send 404 if expressionIndex was -1

Hope this helps!
Send me a message if you want me to change the formatting or have questions :slight_smile:


Thanks, stijndoeleman1050228!

For me, the trouble was understanding where updateElement() and getElementById() functions came from, as I kept googling and searching the code.

For the updateElement(), I had no idea what arguments that function accepted!

Thanks for the artful explanation as well!

I’m having trouble understanding how getIndexById works, could you explain it please?