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 trialAnish Walawalkar
8,534 PointsWhy 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?
1 Answer
Stone Preston
42,016 Pointsjust 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
Anish Walawalkar
8,534 PointsAnish Walawalkar
8,534 PointsSo 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?