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 trialEthan M
10,637 Points404 error with https.get call to treehouse api
I have been trying to connect to the Treehouse API for Andrew's node,js basics course. Whenver I try to connect it doesn't allow me and says 404.
I have changed the request to https instead of http.
Here is my code:
var https = require("https");
var username = "ethanmoffat6";
function printMessage(username, badgeCount, totalPoints) {
var message = username + " has " + badgeCount + " total badge(s) and " + totalPoints + " JavaScript points!";
console.log(message);
}
try {
var request = https.get("https://teamtreehouse.com/" + username + ".json", function(response) {
console.error(response.statusCode);
request.on("data", function(chunk){
console.log("BODY: " + chunk);
});
});
}
catch(e) {
console.log('Catched error: ' + e.message);
}
Let me know any issues please :)
Also, I used try and catch instead of request.on shown in the video.
1 Answer
Ethan M
10,637 PointsIssue has so far been resolved. Changed back to request.on and did https://www.domain.com/username.json/ for the request.
Ethan M
10,637 PointsEthan M
10,637 PointsI have updated my code