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 trialBinu Alexander
4,081 PointsOn a new line use the on method to listen for the error event. Pass in a callback function with one parameter of error.
What am I doing wrong here ?
var http = require("http");
var request =
http.get("http://teamtreehouse.com/chalkers.json", function(response){
console.log(response.statusCode);
}
request.on = ('error', function(res) ) ;
1 Answer
Marcus Parsons
15,719 PointsHi Binu,
The "on" event handler is a method and so it is set with a pair of parenthesis, not an equal sign. You also need a parameter of error
not res
in your callback function. This is what that looks like:
request.on('error', function(error) {});
Binu Alexander
4,081 PointsBinu Alexander
4,081 PointsThanks
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsYou're very welcome! :)