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

getaddrinfo ENOTFOUND teamtreehouse error

Again, could be a typo..but I've gone through the code repeatedly and can't find it.

Keep getting the following error in node console:

events.js:160                                                                                                            
      throw er; // Unhandled 'error' event
Error:  getaddrinfo ENOTFOUND teamtreehouse teamtreehouse:443
       at errornoException (dns.js:29:10)
        at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:7

code:

// 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
//you need to require the node modules needed.  since in this case the node module is https the variable name https is a logical choice
const https = require('https');
const username = "alee2";

//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/{$username}.json`, (response) => {
   console.log(response);

     //Read the data

     //Parse the data

     //Print the data

});

workspace snapshot here

3 Answers

NEVERMIND. found the incredibly stupid mistake......... Except now. using the CORRECT URL I'm getting a 404 and that's where I'm stumped.

NEVERMIND again...another really stupid mistake.

Apologies for the multiple postings on this. i am STILL getting a 404. if I cut and paste the URL into the browser it works. but once written into app.js doesn't. can someone please help.

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

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

//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

});

The solution would work well when used along with the workspace since your browser is already authenticated, For running it on the local, the https.get() needs to be supplied with a header with basic authentication.