Answers for "nodejs how to use await in foreach loop"

3

ts await foreach loop

async function printFiles () {
  const files = await getFilePaths();

  await Promise.all(files.map(async (file) => {
    const contents = await fs.readFile(file, 'utf8')
    console.log(contents)
  }));
}
Posted by: Guest on July-24-2020
0

nodejs how to use await in foreach loop

async function printFiles () {
  const files = await getFilePaths();

  for (const file of files) {
    const contents = await fs.readFile(file, 'utf8');
    console.log(contents);
  }
}
Posted by: Guest on September-30-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language