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 Errors in Node

Ian Blair
Ian Blair
7,411 Points

Using the proper callback from the video example still gives me a Bummer! Try again.

Here is the question. "On a new line use the on method to listen for the error event. Pass in a callback function with one parameter of error."

I can't figure out what's wrong with my code because this is straight from the tutorial video.

Thanks for the help!

app.js
var http = require("http");

http.get("http://teamtreehouse.com/chalkers.json", function(response){
  console.log(response.statusCode);
});

var request = http.get

request.on('error', function(error){
});

Having the same issue here as well.

3 Answers

Jeffrey Smith
PLUS
Jeffrey Smith
Courses Plus Student 15,508 Points

I think you're handling the error correctly. I think the issue is from the previous step. There was already an http.get that was given. Try setting your var request equal to that.

var request = http.get("http://teamtreehouse.com/chalkers.json", function(response){ console.log(response.statusCode); });

Ian Blair
Ian Blair
7,411 Points

Yes that totally fixed it! I guess it shouldn't have let me pass the first test.

Matt Homer
Matt Homer
11,936 Points

or you can shorten with an arrow: request.on('error', error => {});