• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to call POST route functions to fetch API data in order (JS)?

Resolved: How to call POST route functions to fetch API data in order (JS)?

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

When I access(for lack of a better term) the ‘/postUserInput’ POST route, it either does not run getGeoNamesData() until the end, or it doesn’t wait for the API fetch to finish. The data I get from this function is used for simultaneous API calls.
What should I do to make sure these functions run in order?
This is my server file code. It runs in this order according to the console:
first third fourth fifth sixth seventh eigth second
This keeps all my remaining API calls from having the correct data. Please help.
Thanks.

Answer:

Please check the MDN Docs for async functions in Javascript. According to the docs:

Async functions can contain zero or more await expressions. Await expressions make promise-returning functions behave as though they’re synchronous by suspending execution until the returned promise is fulfilled or rejected.


This should run the functions – getGeoNamesData, getCurrentWeatherbitData getPixabayData in order that you expect.

If you have better answer, please add a comment about this, thank you!

hoisting javascript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to give rank on datetime column group by another column with userid in it

24/03/2023

Resolved: Passing 2 functions in onChange in react

24/03/2023

Resolved: Why doesn’t stringstream consume output during hex formatting?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.