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

Nicholas Lansing
Nicholas Lansing
8,901 Points

using the .end() method

why didn't we have to use the .end() method when putting together our other requests to the different routes? We used .json() as the last method in some of the other routes, does this also end the request?

1 Answer

Hi Nicholas Lansing,

You are correct in that using...

res.json(/* some data goes here */)

...to send back data essentially ends a response. I say essentially, because other information can be chained to a res.json() statement (like a status code).

An example of a reason you might use res.end() is if a request has been made to delete a resource. In this case, there would be nothing to send back to the client (as the resource has been deleted), so you would just end the response with res.end().

Hope that helps. And really good question.

Nicholas Lansing
Nicholas Lansing
8,901 Points

Thanks a lot for the response, Brandon! All clear now, that makes sense.