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 Build a Simple Dynamic Site with Node.js Handling Routes in Node.js Populating User Information

Francis Hong
Francis Hong
3,663 Points

Error getting profile

Error: There was an error getting the profile for chalkers. (Moved Permanently)

Seems that it redirects to https for getting the JSON for profile information.

3 Answers

Sean Henderson
Sean Henderson
15,413 Points

To fix this bug in my workspace I had to require both the http and https modules and change everything in profile.js to https except for http.STATUS_CODES:

var EventEmitter = require("events").EventEmitter;
var http = require("http");
var https = require("https");
var util = require("util");

[...]

    //Connect to the API URL (https://teamtreehouse.com/username.json)
    var request = https.get("https://teamtreehouse.com/" + username + ".json", function(response) {
        var body = "";

        if (response.statusCode !== 200) {
            request.abort();
            //Status Code Error
            profileEmitter.emit("error", new Error("There was an error getting the profile for " + username + ". (" + http.STATUS_CODES[response.statusCode] + ")"));
        }

[...]

Thanks Sean Henderson! That did the trick.

Julian Aramburu
Julian Aramburu
11,368 Points

Francis! Treehouse implemented HTTPS on their website! So you must change your http request and ajax calls to https in order for them to work properly :)! Hope it helps!

//Changed comment to answer

Just to add: I was using the 8080 port to listen to -> didn't work :)

Changed it to 3000 and booyah it worked...