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 trialWayne Hite
Courses Plus Student 7,599 PointsWhen running console.log(response.statusCode); I received 404 not 200 as indicated in the video. My code looks identical
Hello, I ran "node app.js" in terminal and it output 404 instead of 200. My code looks identical to the video. Any suggestions what would cause this and how to correct? Here is my code. Thanks!
// Problem: We need a simple way to look at a user's badge count and JavaScript points // Solution: Use Node.js to connect to Treehouse's API to get profile information to print out
// Require https module const https = require('https'); const username = "wayne";
// Function to print message to console
function printMessage(username, badgeCount, points) {
const message = ${username} has ${badgeCount} total badge(s) and ${points} points in JavaScript
;
console.log(message);
}
// Connect to the API URL (https://teamtreehouse.com/waynehite.json)
const request = https.get(https://teamtreehouse.com/${username}.json
, response => {
console.log(response.statusCode);
// Read the data // Parse the data // Print the data
});
5 Answers
latildarich
4,142 PointsHi, make sure you are using a template literal for your http.get url. I also made this mistake and figured out that is what I had done. If it's not in backticks (template literal), it won't read the username correctly.
For example
const request = https.get(`https://teamtreehouse.com/${username}.json`, response => {
console.log(response.statusCode);
// Read the data
// Parse the data
// Print the data
});
KRIS NIKOLAISEN
54,971 PointsIt's hard to tell with the formatting if below is the same code but it produced a status code of 200.
// Require https module
const https = require('https');
const username = "waynehite";
// Function to print message to console
function printMessage(username, badgeCount, points) {
const message = `${username} has ${badgeCount} total badge(s) and ${points} points in JavaScript`;
console.log(message);
}
// Connect to the API URL (https://teamtreehouse.com/waynehite.json)
const request = https.get(`https://teamtreehouse.com/${username}.json`, response => {
console.log(response.statusCode);
// Read the data // Parse the data // Print the data
});
Note: I changed the username to "waynehite". "wayne" resulted in a different account but also resulted in a status code of 200.
jordand
6,894 PointsCheck your teamtreehouse profile privacy settings. Mine was set to private so returned a 404. When I ticked option to allow public got the 200 code.
Sheridan Injeeli
6,556 PointsFor me, the issue was that I had the username wrong it had to be "waynehite" and not something else to work, then you will get a 200 instead of 404.
Matthew Turner
Full Stack JavaScript Techdegree Graduate 16,968 PointsHey latildarich, I did the exact same thing. Thank you for spotting that about the backticks. And one last thing, Go Manchester United, come on you Reds!
nadybee
Full Stack JavaScript Techdegree Student 10,072 PointsI got 404 because my profile was set to private.