1

So I have this question but I cant find a solution. I am scraping my website with axios and cheerio and my url's are very big so I want to use a shortener, I found npm (node-url-shortener) and its very simple to use shortUrl.short('https://google.com', function(err, url){ console.log(url); });

but I dont want to console.log I want to store that value

  $(
    ".searchListing"
  ).each((index, element) => {
    const name = $(element)
      .children(".media")
      .children("a")
      .text();

    let url = $(element)
      .children(".media")
      .children("a")
      .attr("href");

    shortUrl.short(url, function(err, url) {
      return url;
    });

    console.log(??????);


    prices[index] = { name, url };
  });

How can I store the shortened url in my array outside of shortUrl.short module?

Teemu
  • 22,918
  • 7
  • 53
  • 106
C-3PO
  • 35
  • 1
  • 7
  • 4
    [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Andreas Jan 30 '20 at 16:36
  • 1
    Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Klaycon Jan 30 '20 at 17:46

0 Answers0