Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138192

Using data i get from request function in node.JS again until a condition is met

$
0
0

I want to access shopify api using Node.js with request method. I get first 50 items but i need to send the last id of the products i get as a response so it can loop through all the products until we don't have another id (i check that if the last array is not 50 in length.)

So when i get the response of lastID i want to feed that again to the same function until the Parraylength is not 50 or not 0.

Thing is request works asynchronously and i don't know how to feed the same function with the result lastID in node.js.

Here is my code


let importedData = JSON.parse(body);


 //for ( const product in importedData.products ){
  //  console.log(`${importedData.products[product].id}`);    
 //}
 lastID = importedData.products[importedData.products.length-1].id;
 let lastIDD = lastID;
 console.log(`This is ${lastID}`);
 importedData ? console.log('true') : console.log('false');
 let Prarraylength = importedData.products.length;
 console.log(Prarraylength); 
 //console.log(JSON.stringify(req.headers));
 return lastIDD;

});```



Viewing all articles
Browse latest Browse all 138192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>