Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Node.js Basics (2014) Building a Command Line Application Handling Errors in Node

Paul Je
Paul Je
4,435 Points

Not sure how to declare the request variable correctly

The syntax for js I'm not sure as I've only been focused on iOS and now am wondering if this would be a significant obstacle - I'd have to learn Javascript or at least Java in order to have no trouble with these, correct? I'd still like to learn how to go through all the objectives in this code challenge however - I'm the persistent type haha. Thanks in advance!!

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

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

var request = http.get("http://teamtreehouse.com/chalkers.json", function(response)

1 Answer

Thomas Nilsen
Thomas Nilsen
14,957 Points

You're not very far off. It should look like this:

var http = require("http");

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

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