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 Building a Command Line Application Requesting data with https

tezzica
tezzica
3,938 Points

In workspaces, I'm running into a syntax error that I'm not sure what I'm doing wrong. Should I be doing this in vs code

I'm using treehouse's workspace to work through the node.js track before trying on my own in a code editor like vs code. I'm not sure if that may be the problem as the directory doesn't seem to work in the console so I skipped over that. If someone can help point me in the right direction, that would be wonderful.

--------------------------------------This is the code I've placed into app.js
const https = require(https");
function getProfile() {
// Connect to the API url (https://teamtreehouse.com/profiles/csalgado.json)
  const request = https.get(
    "https://teamtreehouse.com/profiles/csalgado.json", 
                            (response) => {
                              console.dir(response);
  }
                           );
//Read the data

//Parse the data

// Print the data 
}
getProfile();


----------------------------------------this is the response from console
treehouse:~/workspace$ node app.js                                                                             
/home/treehouse/workspace/app.js:2                                                                             
const https = require(https");                                                                                 
                           ^^^                                                                                 

SyntaxError: Invalid or unexpected token                                                                       
    at createScript (vm.js:80:10)                                                                              
    at Object.runInThisContext (vm.js:139:10)                                                                  
    at Module._compile (module.js:617:28)                                                                      
    at Object.Module._extensions..js (module.js:664:10)                                                        
    at Module.load (module.js:566:32)                                                                          
    at tryModuleLoad (module.js:506:12)                                                                        
    at Function.Module._load (module.js:498:3)                                                                 
    at Function.Module.runMain (module.js:694:10)                                                              
    at startup (bootstrap_node.js:204:16)                                                                      
    at bootstrap_node.js:625:3            

1 Answer

Steven Parker
Steven Parker
229,744 Points

It looks like a simple case of unbalanced quotes. Try it like this:

const https = require("https");  
tezzica
tezzica
3,938 Points

Thank you, that fixed it.

I can't believe I stared at it for a long time trying to figure it out without noticing the quote missing. I appreciate it!

Steven Parker
Steven Parker
229,744 Points

The syntax coloring can help. Notice that the string is all yellow.