-1

请指导我,我是一个崭露头角的开发者。我必须获取特定文件夹的文件名并将其导出到 main

const fs = require("fs-extra")
let list = []; 
async function getFilename(foldername) 
 {
   list = await fs.readdir(foldername)
   console.log("This should come 1st ")
 }
getFilename(foldername); 
console.log(list,"- files in the folder");

 console.log("This should come 2nd ")
// ....... other coding stuff using list

module.exports = {}

我在这段代码中遇到的问题是我的异步函数是在所有代码行之后执行的,但我需要第一次执行它。

输出

[] - files in the folder 
This should come 2nd
This should come 1st 

我想要的输出

This should come 1st 
[] - files in the folder 
This should come 2nd

提前感谢

4

0 回答 0