javascript - 我可以等待 fs.readdir 但我不知道为什么

标签 javascript node.js vue.js vuejs2 electron

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())

如下所示。

enter image description here

这是 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/

相关文章:

node.js - 在 'end' 事件之后调用“错误”事件?

node.js - Swift http post 请求将空正文发送到服务器

node.js - WIndows 10 上 Msysgit 上的 Node cli

macos - 苹果操作系统 : Install vue cli does work properly

javascript - 在javascript中将时间格式更改为24小时

javascript - 迭代 ul 的所有项目并使用 ajax 调用插入数据库

javascript - 如何在 extjs 中单击按钮后打开一个窗口

vue.js - "export ' 默认值 ' (imported as ' Vue ') was not found in ' Vue'

javascript - removeEventListener 没有按预期工作

javascript - 在 React 中获取调用组件