I am generating an image from google map. This is a promise return method in that I am just looping with the results and storing the result into a new Array variable inside the "then" callback but the response is there but it's not showing in the browser.
Before my google map generating images function was not a promise return function and it was sending the response to browser but it's a promise return function so the response is there but the controller method is not sending a response to the browser.
static providerMapImageGenerator(req, res) {
let providerArr = []
ProvidersRepository.getProviderInfoForMapImage()
.then(providers => {
providers.forEach(provider => {
// Generating image against each entr
MapGenerator.getMapImage(
provider.latitude,
provider.longitude,
provider.name,
provider.providerId
)
.then(res => {
// Saving record after each entry
ProviderMap.create({
providerId: provider.providerId,
url: res.Location
})
// Adding new array for response
providerArr.push({
id: provider.providerId,
url: res.Location,
lat: provider.latitude,
long: provider.longitude,
name: provider.name
})
})
.catch(err => console.log(err, "err in generating image"))
})
// Sending final response against all generated entries to user
res.send(providerArr) // this is going blank to the browser
})
.catch(error => {
// Sending error response if fails
res.send(error)
})
}
I need the providerArr response to display in the browser.
Promise.alland pass it an array of promises to wait for them all to complete