i am new to nodejs and i am trying to form an array of products which are having invalid imageUrls by using "http.get", I am querying my products from my mongodb collection, though i used "Promise" the array is printing first, i am not getting the result form the "hh.get"
here is my code in server side
var Promise = require('bluebird'), hh = require('http-https') mongoose = require('mongoose'), collection = mongoose.model('Collection'); function getInValidImgUrl(prodObj){ return hh.get(prodObj.imageUrl,function(res){ if(res.statusCode == 404){ return { name:prodObj.name, imgUrl:prodObj.imageUrl } } }) } exports.sampleFunc=function(){ collection.find({category:"electronics"}).exec(function(err,products){ if(err){ console.log(err) }else{ var imgArr=[]; //eg:products=[{name:"mobile",imageUrl:"http://somepic.jpg"}] for(var i=0; i<products.length: i++){ imgArr.push(getInValidImgUrl(products(i))); } Promise.all(imgArr).then(results =>{ console.log("IAMGE ARRAY :"+JSON.stringify(results)); //here iam not getting array }) } }); } thanks in advance.