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 Linking Around the Application

Shane Unger
Shane Unger
9,401 Points

Code is correct and works, but I'm getting an error in the console

I've implemented the code in this section, and when I go to a url with only a card number I'm redirected to the full url with the query string, but when that happens I get an error in my console Error: Can't set headers after they are sent, what's causing this and how do I fix it?

Shane Unger
Shane Unger
9,401 Points

oh and this is interesting, it happens as I'm ABOUT to change the url, before I've changed it and hit enter. I'll select the text in the url, hit delete, get ready to enter something else and the Error: Can't set headers after they are sent. pops up in my console

1 Answer

Shawn Rieger
Shawn Rieger
9,916 Points

I'm sure you've already moved onto the next video and in turn, figured this out. Just for other users looking, I'll put the fix here. res.redirect() doesn't stop the execution in the router.get() method, since your also calling res.render() at the bottom of the function, you get an error. So it's a simple fix, just use return...

return res.redirect(`/cards/${id}?side=question`);
Yuichi Narisawa
Yuichi Narisawa
19,548 Points

Thanks! Your answer fixes my error!

You're a life saver Shawn, thanks a lot!

Kenneth Kim
Kenneth Kim
3,795 Points

This is a great help :)