0

Sorry for this naive question, just started learning Nodejs. Could you please let me know why the control never coming to this line - console.log("inside ScrapePage callback") ? Thanks for looking into this and appreciate your help.

var CronJob = require('cron').CronJob;

new CronJob('* * * * * *', function() {
    var collection = db.collection('webpages');
    collection.find({}, function(e, docs) {
// iterate over the webpage list
        for (var i = 0; i < docs.length; i++) {
            var webpage = docs[i];
            (function (webpage) {
                DoStatusCheck(webpage);
            })(webpage);
        }
    });
}, null, true, "America/Los_Angeles");

function DoStatusCheck(webpage) {
    ScrapePage(webpage, function(error, value){
        console.log("inside ScrapePage callback");
    })
}
function ScrapePage(webpage)
{
    return "inside ScrapePage function";
}

2 Answers 2

1

ScrapePage is not calling the callback that you are passing to it.

Edit it to call that second argument.

function ScrapePage(webpage, cb)
{
  cb(null, "value");
}
Sign up to request clarification or add additional context in comments.

2 Comments

Or probably cb(null, "inside ScrapePage function"); without the return.
To return or not return, that is the question ;).
0

You never call the callback. You should have ScrapePage accept a second parameter:

function ScrapePage(webpage, callback) {}

And then call that callback once it has finished doing whatever work it needs to, passing in the error and result:

function ScrapePage(webpage, callback) {

    doSomethingAsync(function (err, result) {

        if (err) {
            return callback(err, null);
        }

        callback(null, result);
    });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.