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 Making a GET Request with http

"http.get" node.js command ran via terminal (OS X, Node.js v5.1.0) doesnt log the error, instead it shows the stacktrace

Here's the code (straight from https://nodejs.org/api/http.html#http_http_get_options_callback, minus the "http://www" in order to trigger an error):

var http = require("http");

http.get("google.com/index.html", function(res) { console.log("Got response: " + res.statusCode); }).on('error', function(e) { console.log("Got error: " + e.message); });

If I run this in Treehouse's Workspace, I get the expected "Got error: connect ECONNREFUSED"

If I run the same code (copy/paste, triple checked), I get this from the terminal:

Shanes-Macintosh:node_dot_js Shane$ node example.js _http_client.js:26 throw new Error('Unable to determine the domain name'); ^

Error: Unable to determine the domain name at new ClientRequest (_http_client.js:26:13) at Object.exports.request (http.js:31:10) at Object.exports.get (http.js:35:21) at Object.<anonymous> (/Users/Shane/GoogleDrive/front-end-learning/node_dot_js/example.js:18:6) at Module._compile (module.js:425:26) at Object.Module._extensions..js (module.js:432:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:313:12) at Function.Module.runMain (module.js:457:10) at startup (node.js:138:18) Shanes-Macintosh:node_dot_js Shane$ node -v v5.1.0 Shanes-Macintosh:node_dot_js Shane$

Same code!! Is it the fact that I have node.js v5.1.0? If so, what is the new methodology to catch errors and why isn't the API updated?

1 Answer

Mariusz Dabrowski
Mariusz Dabrowski
6,132 Points

I just ran into the same issue, can anybody provide some insight?