https://github.com/SimulatedGREG/electron-vue
我用这个模板做electron。
我正在使用这个库。
https://www.npmjs.com/package/fs-extra
https://nodejs.org/docs/latest-v11.x/api/fs.html
通过这个文档,我可以这样写。
await fs.readdir
但是 electron 模板,它使用 electron@2.0.4 而它使用 node@8.9.3。
所以我在这里检查。
https://nodejs.org/docs/latest-v8.x/api/fs.html
看起来函数没有返回 promise。
但我实际上可以在 electron@2.0.4 中使用 fs-extra 等待 fs 函数。
开发和构建。
这是为什么?
结果
console.log(fs.readdir())
如下所示。
这是 promise 。
但是我不知道为什么我可以在electron@2.0.4中做到这一点。
最佳答案
您可以在 Node v8 中使用 fs 模块。返回值将传递给回调函数
const fs = require('fs');
fs.readdir(dir, function(err, list) {
// do your logic with list array
})
关于javascript - 我可以等待 fs.readdir 但我不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56388044/