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 trial

JavaScript Node.js Basics (2014) Building a Command Line Application Making a GET Request with http

Kiyomi Li
Kiyomi Li
22,436 Points

Node.js http.get request results in status code 404

Hi,

When I do the http.get request using my own username, I get the statusCode 404. When I use the chalkers username it works but I was just trying to figure out why my own profile name would not work. I've entered it into the browser and I get a valid page so I don't understand why the request wouldn't work. Here is my code:

var http = require("http");
var username = "kiyomili"

function printMessage(username, badgeCount, points) {
    var message = username + " has " + badgeCount + " total badge(s) and " + points + " points in Javascript."
    console.log(message);
}

//Connect to the API URL (https://teamtreehouse.com/username.json)
var request = http.get("http://teamtreehouse.com/" + username + ".json", function(response) {
        console.log(response)
        //Read the data
        //Parse the data
        //Print the data out
});

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

Thank you.

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Kiyomili;

Do you have your Treehouse profile marked as "Private"? The command line tool doesn't work for me either with your profile name, but I also can't click on your profile name in the forum and have it bring anything up. I believe there is an option in the Profile Settings that can change that.

Ken

Ken Alger
Ken Alger
Treehouse Teacher

Under the Account Settings on the User Profile page (click your Gravatar on the upper right of the screen), there is a menu option for Privacy Settings.

One of the options on that screen is Allow everyone to see your profile. If that box is not checked, the Node.js command line tool will not work for your username. I'll tag Andrew Chalkley and request that he put a note in the Teacher's Notes for the Node.js course about that, I was part of the QA on that course and that skipped my mind as well. Treehouse is on holiday for the rest of this week so it may be a few days before there is a response.

Thanks for pointing that out, and happy coding,

Ken