# Promise.all not working in backend code

**URL:** <https://forum.wixstudio.com/t/promise-all-not-working-in-backend-code/32305>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [December 15, 2019, 2:46pm UTC](https://forum.wixstudio.com/t/promise-all-not-working-in-backend-code/32305 "2019-12-15T14:46:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom66859](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@tom66859](https://forum.wixstudio.com/u/tom66859)\
**Post date:** [December 15, 2019, 2:46pm UTC](https://forum.wixstudio.com/t/promise-all-not-working-in-backend-code/32305/1 "2019-12-15T14:46:15Z")

</div>

The below function “promisall” that uses Promise.all works perfectly on frontend code in a browser but put it in backend code and it doesnt wait for the promises to be fulfilled. If am correct and it doesnt work in backend code, any workarounds or have i messed up.

export function promiseall() {  
let fcaarray = ;  
getarray().then((result) =\> {  
**for** ( var i = 0; i \< result.items.length; i++) {  
fcaarray[i] = getfcainfo(result.items[i].frn);  
}  
Promise.all(fcaarray).then(info =\> {  
console.log(“Here”)})  
});  
}

export function getfcainfo(fcanumber) {  
const url = ‘URL’ + fcanumber;  
**return** fetch(url, {  
method: “get”,  
headers: {  
‘Content-Type’: ‘application/json’  
},  
})  
.then(response =\> response.json())  
}

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [December 15, 2019, 3:49pm UTC](https://forum.wixstudio.com/t/promise-all-not-working-in-backend-code/32305/2 "2019-12-15T15:49:56Z")

</div>

So we can take it that you are using asynchronous code, so please refer to this page about working with promises in Wix Corvid if you have not already seen it.  
[https://support.wix.com/en/article/corvid-working-with-promises](https://support.wix.com/en/article/corvid-working-with-promises)

Also, as you are using Wix Fetch, check that your code is correct there for working within the backend too.  
[https://www.wix.com/corvid/reference/wix-fetch.html](https://www.wix.com/corvid/reference/wix-fetch.html)  
[https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api](https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api)  
[https://support.wix.com/en/article/corvid-web-modules-calling-server-side-code-from-the-front-end](https://support.wix.com/en/article/corvid-web-modules-calling-server-side-code-from-the-front-end)

You can find out more with these links too.  
[https://www.andreasreiterer.at/single-result-with-promise-all/](https://www.andreasreiterer.at/single-result-with-promise-all/)  
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Promise/all](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)  
[https://alligator.io/js/async-functions/](https://alligator.io/js/async-functions/)  
[https://medium.com/@SteelKiwiDev/asynchronous-javascript-programming-with-promises-8c9a3661ccc4](https://medium.com/@SteelKiwiDev/asynchronous-javascript-programming-with-promises-8c9a3661ccc4)  
[https://medium.com/front-end-weekly/callbacks-promises-and-async-await-ad4756e01d90](https://medium.com/front-end-weekly/callbacks-promises-and-async-await-ad4756e01d90)

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [December 15, 2019, 4:04pm UTC](https://forum.wixstudio.com/t/promise-all-not-working-in-backend-code/32305/3 "2019-12-15T16:04:50Z")

</div>

Your’e missing the "return"s

```javascript
export function promiseall() {
let fcaarray = [];
return getarray().then((result) => {
for (var i = 0; i < result.items.length; i++) {
fcaarray[i] = getfcainfo(result.items[i].frn);
}
return Promise.all(fcaarray);
}).then(info => {
console.log("Here");
return info;
});
}

```

---

<div class="post-metadata">

**Author:** ![tom66859](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@tom66859](https://forum.wixstudio.com/u/tom66859)\
**Post date:** [December 15, 2019, 7:21pm UTC](https://forum.wixstudio.com/t/promise-all-not-working-in-backend-code/32305/4 "2019-12-15T19:21:05Z")

</div>

Thx, works a treat now had to change 1 line to get it to work though

```javascript
fcaarray[i] = getfcainfo(result.items[i].frn);

```

to

```javascript
fcaarray.push(getfcainfo(result.items[i].frn));

```

Not sure why but to be honest dont care as it works now :). Thank you so much

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [December 15, 2019, 9:34pm UTC](https://forum.wixstudio.com/t/promise-all-not-working-in-backend-code/32305/5 "2019-12-15T21:34:19Z")

</div>

@tom66859 You’re welcome. I don’t know why the difference. 🙂
