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 Parsing JSON

Gillian Nieh
Gillian Nieh
5,709 Points

Syntax Error

I keep getting a Syntax Error with the following 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

//Require https module
const https = require('https');
const username = 'gilliannieh';

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

// connect to API url (https://teamtreehouse.com/username.json)
const request = https.get(`https://teamtreehouse.com/${username}.json`, response => {
  // read data
  response.on('data', data => {
    body += data.toString();
  });

  response.on('end', () => {
    console.log(body);
    console.log(typeof body);
  });
  // parse data
  // print data

});

This is the error I get: SyntaxError: missing ) after argument list
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)

Any troubleshooting help would be great!

1 Answer

When I run your code I get a ReferenceError of "body" is not defined.

I added let body = ""; and it ran fine.

// read data
  let body = "";
  response.on('data', data => {
    body += data.toString();
  });