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

Ben McMahan
Ben McMahan
7,922 Points

Bug? "Cannot set headers after they are sent to the client"

Noticed in my editor that the terminal was throwing the following error:

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

This is because Andrew sets a redirect but does not return it, meaning that all of the code beyond the redirect runs anyway.

if (!side) {
        res.redirect(`/cards/${id}?side=question`);
    }

should be

if (!side) {
       // RETURN the redirect, exiting out of the function
        return res.redirect(`/cards/${id}?side=question`);
    }

2 Answers

Steven Parker
Steven Parker
231,275 Points

Posting here will get the info to other students, but it may not be seen by the staff. You may also want to report a bug as described on the Support page.

It might even get you a "special Exterminator badge". :beetle:

Ben McMahan
Ben McMahan
7,922 Points

Steven,

Apparently, this was addressed in a subsequent video. Why this wasn't covered in this one is a mystery.

And yes, I'm aware (thanks to your similar replies elsewhere) of maybe earning a badge.

I am hoping that staff reads the forum and this post can help others if they are trying to debug code in this lesson.

Jonathan Drake
seal-mask
.a{fill-rule:evenodd;}techdegree
Jonathan Drake
Full Stack JavaScript Techdegree Student 11,668 Points

That fixed the same issue I was having. Functionality was obviously still present, but the error message in the terminal was irritating. Thanks.