I'm experiencing delays and was wondering how to properly troubleshoot/identify issues.
FETCHES:
async function getWebsite() {
var html = await fetch('https://www.website.com').then(r => r.text());
const doc = new JSDOM(html).window.document;
const links = Array.from(doc.querySelectorAll('.card-title a')).map(({ textContent, href }) => ({ textContent, href }));
return links;
}
THIS READ/SAVE
function readItems() {
try {
if (fs.statSync(idFile)) {
return JSON.parse(fs.readFileSync(idFile));
}
} catch {
return [];
}
}
function saveItems(items) {
fs.writeFileSync(idFile, JSON.stringify(items));
}
COMPARE:
setInterval(async function () {
const links = await getWebsite();
const linkIDs = links.map(l => {
parts = l.href.split('/');
parts.pop();
return parts.pop();
});
var knownItems = readItems();
const newItems = links.filter((link, i) => {
return !knownItems.includes(linkIDs[i]);
});
console.log("new items found: " + newItems.length);
if (newItems.length) {
...
How would I add a timestamp on each time this is output AND log it in a file
console.log("new items found: " + newItems.length); //add timestamp
Basically, I want to verify if the intermittent delays are simply caused by a code issue or a server issue (throttled/firewalled)
question from:https://stackoverflow.com/questions/65948013/troubleshooting-delays-in-node-js-fetching-loop