why does the 1st log print response data, and 2nd log prints function definition instead of response data. is there a way to debug and see the flow?
const https = require("https");
const substr = "spider";
const pageNum = 1;
let list = [];
const fetch = (url) =>
https.get(url, async (res) => {
res.setEncoding("utf-8");
let ttt;
await res.on("data", function (data) {
ttt = data;
});
console.log(ttt); //1st log
return ttt;
});
((substr) => {
totalPages = 1;
pageNum;
for (let i = 1; i <= totalPages; i++) {
const res = fetch(
"https://jsonmock.hackerrank.com/api/movies/search/?Title=" +
substr +
"&page=" +
i
);
console.log(res);//2nd log
}
})("s");