JavaScript Node.js Basics Handling Errors in Node Handling Errors in Node

Moe Ghashim
Moe Ghashim
10,099 Points

Unexpected token ILLEGAL

I'm getting this error but I don't know what I did wrong. Can you help with a guidance?

app.js
const https = require("https");

const request = https.get("https://teamtreehouse.com/chalkers.json", response => {
  console.log(response.statusCode);
});

request.on("error", error => console.error(`error with error: ${error.message}`));

2 Answers

Adam Beer
Adam Beer
11,259 Points

Try without backticks, inside the console.error() write simple error.message. I think now working, like this,

request.on("error", error => {
  console.error(error.message);
});
Hermanos Solis Utrilla
Hermanos Solis Utrilla
14,907 Points

const https = require("https"); https.get("https://teamtreehouse.com/chalkers.json", response =>{ console.log(response.statusCode); });