How to continue saving followers of a channel from a certain point?

I have a little tool written in node.js which sends requests to the twitch API and receives packages. I have this function which saves the followers of a given channel https://dev.twitch.tv/docs/v3/reference/follows#get-channelschannelfollows . My problem is that sometimes I need to restart the tool, but I don’t want to get packages with followers from the beginning. Is there a way with the help of the cursor to start to receive packages from a certain point?

try {
function findCursor() {
    db.collection('channelmodels').findOne({_id: currentChannel}, function (err, userData, user) {
        if (userData == null) {
            console.log("channelmodel not in DB");
        } else if (userData != null) {
            cursorInDB = userData.cursor;
            console.log("cursor " + cursorInDB);
            alreadyInDB = true;
        }
    });
}

console.log("newstart " + newStart);
findCursor();
if (cursorInDB != null && newStart) {
    followerURL = beginningOfURL + currentChannel + "/follows?cursor=" + cursorInDB + "&direction=ASC&limit=" + 
        packageSize;
}
 } catch (e){
    console.log(e.name);
   var fs = require('fs');
   fs.appendFile("undefinedLog.txt",  "undefined property at findCursor body._cursor"  + new Date().toLocaleString() + 
    " 
   "+e.name + "\r\n");

   }

I have this piece of code, but either I am doing something wrong or twitch isn’t consistent with the cursors, because sometimes after a restart it begins to save the followers from the last saved cursor, and sometimes it doesn’t.

Thank you in advance!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.