TypeError: callback is not a function when calling a callback function

345 views Asked by At

Having trouble with this piece of code. Whenever i run it it says "TypeError: callback is not a function". I've tried figuring it out myself but didn't have much luck there. I'd really appreciate if someone can help me!

var getPData = require('aliexpress-product-scraper');

function getProducts(ids, data, count, callback) {
    getPData(ids[count]).then(res => {
        data.push({ title: res.title, description: res.description, image: res.images[0] })
        console.log(`[${count}]`)
        count++

        if (count >= ids.length) {
            callback(data)
        }
        else {
            getProducts(ids, data, count)
        }
    })
    .catch(err => console.error(err))
}

getProducts ([
    4000021893815, 33003633828,
    4000525729095, 33058311152,
    32880245829, 4000651037514,
    4000209825247, 4001139242149,
    33035136283, 33003282862,
    33032105966, 33044615891
], [], 0, (data) => {
    console.log(data)
})

The purpose of the code is to collect data about products from aliexpress, if that helps.

0

There are 0 answers