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

Why does this return a syntax error at JSON.parse(body)?

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

const request = https.get('https://teamtreehouse.com/${username}.json', (response) => { 

        let body = "";

        response.on('data', (dataChunk) => {
        body += dataChunk.toString();   
        });

        response.on('end', () => {
            const myDataObject = JSON.parse(body);
            console.dir(myDataObject);
        });
});

... I just don't see it :-/

Thanks in advance!

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, francisobrien ! It looks like you're doing terrific thus far! There's a very minor issue which is causing the problem and it is in the URL you are accessing. It's the difference between a single quote and a backtick.

You wrote:

 https.get('https://teamtreehouse.com/${username}.json'

But the punctuation before the https and after the json shouldn't be a single quote ', it should be a backtick. Notice how they slant slightly:

 https.get(`https://teamtreehouse.com/${username}.json`

Hope this helps! :sparkles:

Got it! Eagle eyes! Thanks, Jennifer