截图如下:

原因如下:记住"./uploads" 后要加一个/

 fs.stat("./uploads/" + files[i], function(err, stats) {

解决:

var fs = require("fs");

exports.getAllAlbums = function(callback) {

    // 找到所有文件夹
fs.readdir("./uploads", function(err,files) {
if (err) {
callback("没有找到uploads文件夹", null);
}
var allAlbums = [];
(function iterator(i) {
if (i == files.length) {
console.log(allAlbums);
// return allAlbums;
callback(null,allAlbums);
return;
}
fs.stat("./uploads/" + files[i], function(err, stats) {
if (err) {
callback("找不到文件"+files[i], null);
}
console.log(stats);
if (stats.isDirectory()) {
allAlbums.push(files[i]);
}
iterator(i + );
});
})();
});
// return ["小猫", "小狗"];
}

Node.js报错TypeError: Cannot read property 'isDirectory' of undefined的更多相关文章

  1. Node中使用MySQL报错:TypeError: Cannot read property 'query' of undefined

    Node中使用MySQL报错: TypeError: Cannot read property 'query' of undefined at /Users/sipeng/Desktop/彭思/201 ...

  2. VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法

    正常情况下在data里面都有做了定义 在函数里面进行赋值 这时候你运行时会发现,数据可以请求到,但是会报错 TypeError: Cannot set property 'listgroup' of ...

  3. JS报错:Cannot read property 'type' of undefined

    在做图片上传功能的时候,遇到了JS无法识别图片type的问题,在使用过程中是没有问题的,但是不知道为什么浏览器的Console报这个错误: Uncaught TypeError: Cannot rea ...

  4. 使用webpack命令打包时,报错TypeError: Cannot read property 'presetToOptions' of undefined的解决办法

    我只安装了webpack,没有安装webpack-cli,第一次输入webpack打包时,提示 One CLI for webpack must be installed. These are rec ...

  5. vue表单校验提交报错TypeError: Cannot read property 'validate' of undefined

    TypeError: Cannot read property 'validate' of undefined at VueComponent.submitForm (plat_users.html: ...

  6. vue报错TypeError: Cannot read property 'protocol' of undefined

    错误信息如下所示: isURLSameOrigin.js?3934:57 Uncaught (in promise) TypeError: Cannot read property 'protocol ...

  7. vue报错TypeError: Cannot read property '$createElement' of undefined

    报错截图: 这个错误就是路由上的component写成了components

  8. react报错 TypeError: Cannot read property 'setState' of undefined

    代码如下: class test extends Component { constructor(props) { super(props); this.state = { liked: false ...

  9. 73.node.js开发错误——TypeError: Cannot set property 'XXX' of undefined

    转自:https://blog.csdn.net/fd214333890/article/details/53467429

随机推荐

  1. javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class com.javaliao.portal.model.TbLogVisit! T

    javax.jms.jmsexception:无法从内容生成正文.可序列化类不可用于代理原因:java.lang.ClassNotFoundException: 禁止类com.javaliao.por ...

  2. selenium之python源码解读-expected_conditions

    一.expected_conditions 之前在 selenium之python源码解读-WebDriverWait 中说到,until方法中method参数,需要传入一个function对象,如果 ...

  3. Centos 安装JDK(最最最最最方便的方法)

    1.下载rpm安装文件,链接:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2 ...

  4. Postgresql pg_dump 与 pg_restore 使用举例

    pg_dump备份 备份本地osdb数据库,全备份,不需要密码 pg_dump osdb > osdb.sql 备份远程osdb数据库 pg_dump -h 192.168.122.1 -Uos ...

  5. webpack 性能优化小结

    背景 如今前端工程化的概念早已经深入人心,选择一款合适的编译和资源管理工具已经成为了所有前端工程中的标配,而在诸多的构建工具中,webpack以其丰富的功能和灵活的配置而深受业内吹捧,逐步取代了gru ...

  6. 块状链表 bzoj 3343教主的魔法

    //块状链表//分块排序,然后每次查找时在暴力查找头和尾两个块.//中间那些块,因为有序所以只需2分查找即可.我用的是lower_pound();//插入是,也是头和尾暴力插入,中间那些加到一个累计里 ...

  7. 【概率论】5-3:超几何分布(The Hypergeomtric Distribution)

    title: [概率论]5-3:超几何分布(The Hypergeomtric Distribution) categories: - Mathematic - Probability keyword ...

  8. 【原创】go语言学习(十二)struct介绍1

    目录: struct声明和定义 struct的内存布局以及构造函数 匿名字段和struct嵌套 struct与tag应用 struct声明和定义 1.Go中面向对象是通过struct来实现的, str ...

  9. 视觉SLAM十四讲(三)——三维空间刚体运动(下)

    理论部分请看 :三维空间刚体运动 一.Eigen的使用 首先安装 Eigen: sudo apt-get install libeigen3-dev 一般都安装在 /usr/include/eigen ...

  10. Freestream边界条件【翻译】

    翻译自:CFD-online 帖子地址:http://www.cfd-online.com/Forums/openfoam-solving/93093-freestream-boundary-cond ...