I recently downloaded scrape-it from NPM as a dependency and I'm trying to store the results in a variable instead of using a callback function. When I run the code snippet provided in the scrape-it documentation:
var myVar = scrapeIt("http://ionicabizau.net", {
title: ".header h1"
, desc: ".header h2"
, avatar: {
selector: ".header img"
, attr: "src"
}
}).then(page => {
return page;
});
console.log(myVar);
I receive the output: Promise { <pending> }. I've also attempted to use 'await' before calling the scrapeIt() function, but this resulted in a 'Unexpected identifier' syntax error.
Oddly enough, when I tried this code on the RunKit + npm platform, it worked perfectly fine. However, executing it locally on my machine throws errors. I've double-checked all dependencies and even reinstalled the package, yet I can't figure out what's going wrong. Any help would be greatly appreciated.
While this issue does relate to the asynchronous nature of JavaScript, the main focus is on improving my understanding of working with promises.