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 trialTed Moxon
18,203 PointsIm not getting the same errors.
Im on video 1 of Stage 3 in the Node class. Is this video outdated or something? I am following along. Wrote out exactly as it is in the video. Yet I don't get the same error message. I'm not getting anything at all its just a blank line
I am running this on my local computer btw. in Visual Studio Code from the Code terminal Yes Node is installed on my computer and it runs fine. I wonder if its just because its from within Code
my code look like this:
// 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');
//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);
}
function getProfile(username) {
// Connect to the API URL (https://teamtreehouse.com/username.json)
const request = https.get(`https://wwwteamtreehouse.com/${username}.json`, response => {
let body = "";
// Read the data
response.on('data', data => {
body += data.toString();
});
response.on('end', () => {
// Parse the data
const profile = JSON.parse(body);
// Print the data
printMessage(username, profile.badges.length, profile.points.JavaScript);
});
});
request.on('error', error => console.error(`Problem with request: ${error.message}`));
}
const users = process.argv.slice(2);
users.forEach(getProfile);
1 Answer
Neil McPartlin
14,662 PointsHi Ted. Your code is working fine here with me. I'm on Windows 7 and I too use the integrated terminal that comes with Visual Studio Code. I note one gets the same symptom you describe if you accidentally just type... node app.js
So with your code untouched, when I enter... node app.js chalkers
I get...
Problem with request: getaddrinfo ENOTFOUND wwwteamtreehouse.com wwwteamtreehouse.com:443
And if I fix the error you deliberately inserted i.e. wwwteamtreehouse.com -> teamtreehouse.com then type... node app.js chalkers
I get...
chalkers has 209 total badge(s) and 5966 points in JavaScript
You clearly do have node installed otherwise Windows would report 'command not found'. Please come back if node app.js chalkers still results in nothing.