an express server...
                  
                  
                  
                  
                  
                  On a post route
                  
                  
                  /postImage 
                  
                  
                  
                  
                  
                  When a number say "n" is passed and when I call my function inside 
                  
                  
                  
                  
                  
                  app.post(.......){
                  
                  
                      let resp = getImage();
                  
                  
                      res.send(JSON....);
                  
                  
                  }
                  
                  
                  
                  
                  
                  I am getting a pending promise object.. 
                  
                  
                  
                  
                  
                  function getImage(x){
                  
                  
                       // pushes resp to resp arr x times 
                  
                  
                       resp = fetchfromAPI();
                  
                  
                       return respArr;
                  
                  
                  } 
                  
                  
                  
                  
                  
                  
                  
                  
                  And... 
                  
                  
                  fetchfromAPI(){
                  
                  
                     let urlarray = []  ;
                  
                  
                      return <api call>.then(
                  
                  
                          (results) => {
                  
                  
                            urlarray.Push(result);
                  
                  
                            return urlarray;
                  
                  
                  }) 
                  
                  
                  } 
                  
                  
                  
                  
                  
                  
                  
                  
                  How can I get the. Array of urls as a response to my post request?
                  
                  
                
I think the problem is in the fetchFromAPI function, coz you try using async process inside the sync function, there's two alternatives 1. Change your function to async function, and await the api call process 2. Add callback parameter and call it when the api call has been done
Обсуждают сегодня