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 Node.js Basics (2014) Building a Command Line Application Handling Parsing and Status Code Errors

Anish Walawalkar
Anish Walawalkar
8,534 Points

Why are the response.on methods not inside the if(response.statusCode == 200) {} statement?

Shouldn't the response.on methods only be called if the request actually sends a response in which case the statusCode will be 200?

Anish Walawalkar
Anish Walawalkar
8,534 Points

So just out of curiosity does the response object have a readyState value like in the case of AJAX or is that where the response.on('data'......) and response.on('end', ....) come in?

1 Answer

Stone Preston
Stone Preston
42,016 Points

just because the response is not 200 does not mean there is no response. for example there can be a response of Not Found (404), which is not 200 but there is still a response