I have two files; server.js and scrape.js, below are the code snippets as they currently stand.
server.js:
const scrape = require(\"./scrape\");
asy
I believe your go
function isn't returning any value.
You're calling request(options).then(...)
, but what follows from that promise is never returned by go
. I recommend you add a return
statement:
go = async () => {
const options = {
uri: "http://www.somewebsite.com/something",
transform: function(body) {
return cheerio.load(body);
}
};
// The only difference is that it says "return" here:
return request(options)
.then($ => {
let scrapeTitleArray = [];
$(".some-class-in-html").each(function(i, obj) {
const data = $(this)
.text()
.trim();
scrapeTitleArray.push(data);
});
return scrapeTitleArray;
})
.catch(err => {
console.log(err);
});
};