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 trialPlacid Rodrigues
12,630 PointsCannot generate Error.
Before implementing the error handler, I tried to test the connection error. I removed the "http://" part from the url and tested in the console. But I don't see any Unhandled error event or any stack traces. Can anyone tell me why?
My code is:
var http = require("http");
var username = "chalkers";
function printMessage(username, badgeCount) {
var message = username + " has " + badgeCount + " total badges";
console.log(message);
}
// Connect to API URL
var request = http.get("teamtreehouse.com/" + username + ".json", function(response){
console.log(response.statusCode);
// read data
// parse data
// print data
});
I only see the status code 400. If I remove the console.log(response.statusCode);
part and test it, just nothing shows up in the console.
Any guidance, please?
Placid Rodrigues
12,630 PointsHi Jason,
Thanks for your endeavor.
My Node.js version is 0.10.33
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsI checked the downloads page and that version goes back to october 2014.
There could be some differences in the code from back then which is preventing you from getting the same results as in the video.
I would suggest that you try to find some node update instructions for the operating system you're using.
I updated to the latest 0.12.2 and I still see the error message as expected.
I'm on windows and found this page helpful: http://exponential.io/blog/install-or-upgrade-nodejs-on-windows/
Jason Anello
Courses Plus Student 94,610 PointsI checked the earlier videos and the version in workspaces is 0.10.32 which is very similar to your version. My answer is unlikely to help then.
Are you using workspaces?
Gary Calhoun
10,317 PointsI am version 0.12.7 on windows and when I run node app.js in command prompt I either get a 400 or a 200 when its good I can't replicate that error message either.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Placid,
Unfortunately I can't duplicate this behavior. I copied your exact code into a "test.js" file I have on my desktop and I ran the command "node test.js"
I was able to get an error message.
I don't know if the version of node you're running would have anything to do with it.
My version is 0.12.0
Could you type "node --version" and see what you have?
This may be useful to anyone else trying to help.