callback does not execute after request finished. Please give me suggestions. How can I execute the callback method after request is finished successfully. Thanks in advance.
async function sendSearchRequest(config, search_url, message, ambiente, callback){
const options = {
'method': 'POST',
'url': 'https://www.example.com',
'headers': {
...
},
form: {...}
};
await request(options, function (error, response) {
if (error) {
consolel.log("Error!----------------------------", error);
}
const $ = cheerio.load(response.body);
const szPages = $('#divResultadosSuperior').find('table > tbody > tr > td:first-child').text();
const szTexts = szPages.split(' ');
const nPages = Math.ceil(szTexts[szTexts.length - 2] / 10);
console.log("This is Number of Page: -----------", nPages);
for(let i = 1; i <= nPages; i ++)
{
downloadPDFsOfPage(i, response.headers['set-cookie'][0], pdf_lists, search_url, message);
}
//await scrapPdf(response.body, response.headers['set-cookie'][0]);
}).end(callback())
}