dataGroup.forEach(async function(data) { CNumber = data.CNumber; console.log(`Sending CNumber ${CNumber}`); // cDetect(CNumber); fs.readdir("./data", (err, files) => { files.forEach(file => { console.log(file); }); }); // Execute single number search }); I have an array of CNumbers which is in dataGroup. I'm running forEach on dataGroup and selecting CNumber. On 3rd line I have logged the number I receive and it is the expected data. But when execution moves to fs.readdir it doesn't work as expected.What happens is: CNumber received from from forEach is printed all at once then fs.readdir is executed. But it was supposed to execute 3rd line then execute fs.readdir then log all filenames in that dir then again get next CNumber then again log all files inside dir. When execution is inside files.forEach each file is grabbed and is checked with the CNumber. That part of code I have removed as there's more task in it.Here's the output of current code:https://gist.github.com/CovertCode/9431f0634f8019c116c86fcd5567beb6Can someone help me with this code :/
Submitted January 15, 2020 at 02:15PM by pverma8172
No comments:
Post a Comment