I have a sails.js web application and I have a crawling function that get the title of a website then I want to return that value to the view.
I tried to assign the function to a variable and return it but always it says undefined.
const Crawler = require("crawler");
let c = new Crawler({
    maxConnections : 10,
    callback : function (error, res, done) {
        if(error){
            console.log(error);
        }else{
            let $ = res.$;
            let title = $("title").text();
        }
        return title
        done();
    }
});
module.exports = {
    testapi: function (req, res) {
        title = c.queue('http://www.agounichams.ml');
        sails.log(title);
        return res.send(c.title);
    }
}
 
     
    