JavaScript Node.js Basics Building a Command Line Application Capturing Command Line Arguments

SyntaxError: Unexpected token N in JSON at position 0 - Please help

My 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

const https = require('https');

function printMessage(username, badgeCount, point){
  const message = `${username} has ${badgeCount} total badge(s) and ${point} points in javascript`;

function getProfile(username){             
  // Connect to the API URL (
  const request = https.get('${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);


what have i done wrong here? Thanks in advance :)

3 Answers

Inside your getProfile function, you are using Template String but with single quotes '${username}.json' in order to make the Template Strings work replace the single quotes with backtick,

Daniel Paez
Daniel Paez
Pro Student 4,213 Points

Also, if anyone else is still running into this issue after evaluating the code it could be the username you are passing into the function. A non-existent one will give you the same error.

Jasmine Martin
Jasmine Martin
13,755 Points

oh wow. That was golden thanks! I was using chalker instead of chalkers :(

Many thanks for your time and input :)