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 2017 Building a Command Line Application Making a GET Request with https

Video example returns 404 status code in node.js console (but the URL works if pasted into the browser)

CLICK HERE FOR SNAPSHOT

Here is the code:

//function to print message to console:
function printMessage(username, badgeCount, points) {
const message = `${username} has ${badgeCount} and ${points} points in JavaScript`;
  console.log(message);
}

//printMessage("chaulkers", 100, 2000);

//connect to the API URL (https://teamtreehouse/alee2.json)
const request = https.get(`https://teamtreehouse.com/${username}.json`, response => {
   console.dir(response);
   console.log(response.statusCode);

     //Read the data

     //Parse the data

     //Print the data

});

Keeps returning 404 and I can't for the life of me figure out why. used backticks. couldnt get the the node.js response to copy and paste into this message (not frustrating at all).

Thank you for any assistance. Especially since I can't move on in this lesson until this works.

pasted code from solution download and still get a 404

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Never mind! I stand corrected. When I go to https://teamtreehouse.com/alee2.json I get a 404 even in the browser. I also cannot choose to view your profile from within the Community forums which suggests to me that you have your privacy settings on your profile to not be public. If you try to access your json (which doesn't seem to be public) you will and should receive a 404.

It may be allowing you to see your json in your browser because you have an active session with Treehouse, but your profile needs to be public for this to work correctly.

Is this helpful? :smiley:

Jennifer Nordell THAT IS IT!! thank you!! This should be in the instructors notes for that video. I don't even remember changing the privacy setting but apparently i did.

MANY THANKS!

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I feel like you're doing really well and likely fell victim to a typo here. In the code you have posted, you have not defined the variable username. There is, however, a call to the printMessage function which passes in "chaulkers", however, no such user name exists on Treehouse. I believe you meant to call this and pass in "chalkers".

Take a look at:

https://teamtreehouse.com/chaulkers.json

VS

https://teamtreehouse.com/chalkers.json

The bright side is that it is working! Because of the misspelling a 404 is exactly what it should return.

Take a look toward the end of the video where he sets up a const to hold the user name. And try that but with alee2.

Hope this helps! :sparkles:

Thank you...Sorry, I didn't paste that far up (I thought I had). I did actually declare the variable and require https. The printmessage function worked fine as it was passing in the misspelling into the template literal along with the other arguments (and in the code above was commented out). Please see snapshot for the full code as well.

here's the top of the code. Any other ideas on what I'm doing wrong? I even pasted the code from the solution and it's still giving me a 404. I'm utterly beyond frustrated at this point. Thanks again for the response.

const https = require('https');
const username = 'alee2';