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

devina christabela
devina christabela
12,526 Points

The `console.error` not showing the error

Hi I'm following the video codes, but why it doesn't show any error on the console.error when I run it on my computer, at workspaces it work fine? I'm using linux with node v8.10.0..

const https = require('https');

function printMessage(username, badgeCount, points) {
    const message = `${username} have ${badgeCount} badges and total points ${points}`; 
    console.log(message);
}

function getProfile(username) {
    const request = https.get(`https://wwwteamtreehouse.com/${username}.json`, (resp) => {
        let body = "";
        resp.on('data', data => {
            body += data.toString();
        });

        resp.on('end', () => {
            const profile = JSON.parse(body);
            printMessage(username, profile.badges.length, profile.points.total);
        });
    });

    request.on('error', err => {
        console.error(err.message);
    });
}

const users = process.argv.slice(2);
users.forEach(getProfile) 

1 Answer

Not sure if the error that is meant to occur is the incorrect request URL, but it is missing a dot/period between www and teamtreehouse.com.

It's likely this is throwing an error that can't be handled by the https module.