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 trialShane Unger
9,401 PointsCode 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?
1 Answer
Shawn Rieger
9,916 PointsI'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
19,548 PointsThanks! Your answer fixes my error!
Tom Couillard
19,866 PointsYou're a life saver Shawn, thanks a lot!
Kenneth Kim
3,795 PointsThis is a great help :)
Shane Unger
9,401 PointsShane Unger
9,401 Pointsoh 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