JavaScript Node.js Basics Handling Errors in Node Handling the Error Event in Node

lukej
lukej
28,606 Points

Error in CodeChallenge: Handling Error Events in Node.js

I don't know what might be wrong with this code. But the unit test always says:

"Bummer: You didn't declare the var, const or let variable correctly."

Anybody have any ideas?

Challenge Task 1 of 3 Create a variable request that stores the result of the get method.

const https = require("https");

https.get("https://teamtreehouse.com/chalkers.json", response => {
  console.log(response.statusCode);
  let request = '';
  response.on('data', data => {          
  request += data;
  });
});
lukej
lukej
28,606 Points

I figured it out. Just in case anybody has a similar problem.

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.message);
});