0

I have this function:

app.post('/list', function(req,res){
var imagelist=[]
var list=req.body.list
console.log("posted this: "+list)   
list=list.split("\n")
console.log("starting for each")
list.forEach(function(card) {       
    mtg.card.where({name:card}).then(cards=> {
        var url =cards[0].imageUrl
        if(url){
        imagelist.push(cards[0].imageUrl)
        } else{
            console.log("no such card")
        }
        console.log("get url: "+imagelist)      
    })  
})
console.log("render"+imagelist)

    res.render('list',{
        list:list,
        imagelist:imagelist[0]
  })
})

this functions results in this log:

server start
posted this: squee
starting for each
render
get url: http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=370461&type=card

the render function is called before the imagelist is filled, I don't know why.

all code can be found here: https://github.com/JasonElting/mtgapp

user3294794
  • 1,159
  • 1
  • 6
  • 5

0 Answers0