Node.js Tutorial — Run an Async Function in Array.map()

preview_player
Показать описание


There are situations where you want to run asynchronous functions within map, e.g. updating a list of models and push the changed information back to the database or request information from an API that you want to use for further operations.

Sample Code on GitHub

Dedicated tutorial with code snippets

----------------------------------------

Checkout 380+ technical in-depth tutorials:

Subscribe for two new videos every week:

----------------------------------------

Follow us on social media to get updates on new content:

----------------------------------------
Рекомендации по теме
Комментарии
Автор

Thank you so much for this! Promises are so hard to learn for beginners

VivekGawande
Автор

Had a similar problem. Solved it with ur simple one line solution THANK YOU sooomuucchhh.

thangzathang
Автор

Thank you, simple and elegant solution saved my day!

stoiccoder
Автор

Thanks!!! I was really very stuck with a request, and now I was able to solve it thanks to this video. Cheers!

sebastianalfaro
Автор

lifesaver
edit: holy shit i've actually commented this like 2 months ago when i encountered the same issue. dang i need some rest, i got very forgetful when im tired lol

mrlon
Автор

Thank you so much ! I was banging my head with this over a coding challenge I have to do.

qcmira
Автор

Thank you, I didn’t realize how powerful map was and plan to use it..a lot. I’m into chatbots and I’m using Botkit by howdy. It’s wonderful but trying to learn node.js lol didn’t know it going in but determined too make the bot do things I need it to do. I’d love to see how to handle json request/response data in node.js. Botkit allows for message attachments and I really feel that asking my bot to fetch me data is/has been the future. The whole asking a chatbot for info over simply looking it up is interesting to me and I think that is powerful.

KevinMarchese
Автор

hi, map itself is not promisable ? it depends on the await function run inside, which in this case is axios which does have a promise wrapper... in your example it makes it seem that any function run inside a map function is promisable.

rickyu
Автор

Thank you so much for your efort tô help us.... Help me a lot...

CarlosHenriqueCoelho
Автор

Thank you! Really helpful, appreciate it!

bjornericcom
Автор

I'm an idiot to find out what's going on after 4 hours I search this on YouTube and thanks!

loeiks
Автор

Thanks man, I have 2 days working and it takes me less than 10 minutes solve it

elisevlogs
Автор

Hmm did I miss somthing? await Axios should return data, instead of promise. no?

GintsPolis
Автор

Thank you for the tutorial, maybe you should change Map.array() to Array.map() on the title

youcam