蓝鸟-fs.readdir().then-无法读取未定义的属性 [英] bluebird - fs.readdir().then - cannot read propery then of undefined
问题描述
I am trying to promisify the fs readdir function using bluebird. I just want to read all the files in a directory, and then output the array with console.log
.
const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs'));
fs.readdir('./XML').then(function(err, directories) {
console.log(directories);
});
我得到以下输出:
fs.readdir('./XML').then(function(err,directory){ ^
fs.readdir('./XML').then(function(err, directories) { ^
TypeError:无法读取未定义的属性"then" 在对象. (/Users/shooshte/Sportradar/notThatKindOfPeon/bluebird.js:4:20) 在Module._compile(module.js:570:32) 在Object.Module._extensions..js(module.js:579:10) 在Module.load(module.js:487:32) 在tryModuleLoad(module.js:446:12) 在Function.Module._load(module.js:438:3) 在Module.runMain(module.js:604:10) 运行时(bootstrap_node.js:394:7) 在启动时(bootstrap_node.js:149:9) 在bootstrap_node.js:509:3
TypeError: Cannot read property 'then' of undefined at Object. (/Users/shooshte/Sportradar/notThatKindOfPeon/bluebird.js:4:20) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3
我在做什么错了?
推荐答案
fs.readdirAsync('./XML').then()
约定的方法名称将是带有后缀的原始方法名称(默认为异步").
The promisified method name will be the original method name suffixed with suffix (default is "Async").
这篇关于蓝鸟-fs.readdir().then-无法读取未定义的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!