Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics Parameters, Query Strings, and Modularizing Routes Card Template

Brian Patterson
Brian Patterson
19,588 Points

This video was really poorly explained.

I kinda understand query strings but I must admit I was completely lost about how he got "side". Where does that come from?

// Here, we're setting either the string "answer" or the string "question" to a variable called side
  const side = req.query.side; // "answer"

How does side have access to "question" or "answer" ? Apologies if this is a dumb question but I need more clarification.

6 Answers

As you probably suspect, side is an arbitrarily named variable. It's a good, arbitrary name because it describes exactly what value it holds — either the question side of the flashcard, or the answer side of the flashcard. But we could also use something like faceCard instead of side.

The variable is first introduced to the web app during runtime when the user requests either side of the flashcard to be displayed.

What may be confusing is that at this stage of the code, the only way the user can make this request is to actually type out the URL with the query string in full:

http://localhost:3000/cards/1?side=question

As Andrew states at 01:05 in the video:

If a query string is in the request, it will be in the request object under the query property.

And if we run console.log(req.query); we will receive:

{ side: 'question' }

This is how side, the key, has access to, in this example, question, the value — it's all contained in, again, "the request object under the query property."

Of course, in a completed web app, manually entering a URL with a query string would never be demanded of the user. More likely, we will eventually add a button or link that, when clicked, will send that same URL to the server rather than having to manually type it in to the browser.

I agree. Very poorly explained. He starts typing and half mentions what he is doing.

Matthew Turner
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Matthew Turner
Full Stack JavaScript Techdegree Graduate 16,968 Points

I don't want to be too harsh on Andrew, but his courses are the only ones I struggle with. They take me 3 to 4 times as long to migrate through because of typos, areas that he "glosses over" and very important information he throws in passingly. He isn't precise enough.

I'm also one of the ones who are frustrated and made it to the questions section under the video. Let us not be too harsh with Andrew and give him a pass on this one. He is one of my favorite teachers here @ Treehouse. And my big thanks to everyone who finds time to explain all the "dead zones" in lessons.

Hi, If you are struggling to understand the use of req.params , req.query here is a short yt video that helped me a lot! https://www.youtube.com/watch?v=9jXnf8Qmqmg

Thank me later! :)

Likely the query string for this particular route contains a 'side' query parameter.

/someRoute?side="answer"