Tuesday, 18 April 2017

forEach and async function calling

const files = fs.readdirSync('some/directory');
console.log('here1');
files.forEach(async (file) => {
  await myFunc();
  console.log('here2');
});
console.log('here3');

I have two files in the directory. The output is:

here1
here3
here2
here2

Is there a way to produce the order:

here1
here2
here2
here3



via Karl Morrison

No comments:

Post a Comment