I am working on a small project making request to API and fetch data but compiler not entering into the request.
This is my code :
const https = require("https");
function getUserData(username) {
  let error = "";
  let json_data = {};
  try {
    const req = 
       https.get(`https://xteamtreehouse.com/${username}.json`, res => {
     let data = "";
  if (res.statusCode == 200) {
    res.on("data", in_data => {
      data = in_data.toString();
    });
    res.on("end", () => {
      json_data = data;
    });
  } else {
    error = `An ${res.statusCode} error occured!`;
  }
   });
    req.on("error", e => {
      error = e.message;
    })
  } catch (e) {
    error = e.message;
  }
  if (error)
    return false;
  return json_data;
}
console.log(typeof getUserData("chalkers"))
Output : When I run that code its not showing "string" instead showing "object" that means the get request is not working please help.
 
    