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

On a new line use the on method to listen for the error event. Pass in a callback function with one parameter of error.

I can't see what is wrong, here, could someone help me please?

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


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


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

1 Answer

Ops, I guess I just over did it. The right code is:

const https = require("https");

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

request.on('error', error => console.error());