✅ – dmikester1 – 16-27 Oct 12
Once again, here I am struggling with async/await and promises. I have a Node endpoint that ran a bunch of code to read some files from a directory and do some processing and it was all working just fine. Then I realized I needed to abstract that code out so I could call it from multiple places. And now I cannot get a result back from that endpoint. I know it has to do with how I am handling the promises.
19 Replies
Here is the endpoint code:
and here is
getMisfitCount()
:
when I log out misfitCountData
in the endpoint, it is undefined and gets output before I see sending back:...
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
targetFiles gets used a few lines down:
targetFiles.forEach((file, index) => {
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I understand that. I am not accessing targetFiles outside the function.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
that
});
is closing the files.filter
blockUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
yeah, sorry about that
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
shoot, i deleted my return when i was cleaning up my code
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
i edited the function to show my return
i see 'sending back results' after i see 'getting misfit count...'
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
ohhh, so you are saying i need to do
return fs.promises.readdir(misfitsFolder)....
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
holy crap, that was it!
thank you so much!!!
struggled way too long on that one! 🙂
This question has an answer! Thank you for helping 😄
If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1029792352363106324
This thread hasn’t had any activity in 12 hours, so it’s now locked.
Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1029792352363106324
Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question:
https://stackoverflow.com/help/how-to-ask
http://wp.me/p2oIwo-26