截图如下:

原因如下:记住"./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. XSLT可扩展样式表语言转换 System.Xml.Xsl、XslCompiledTransform类

    XML文件 books.xml: <?xml version="1.0" encoding="utf-8" ?> <bookstore> ...

  2. Wireshark远程抓包

    1.被监控主机上,在安装目录下点击rpcapd.exe,运行server服务,并关闭防火墙 2.监控机器上,Capture Options,点击Manage Interfaces,弹出如下对话框 选择 ...

  3. pyharm 上运行 npm 配置方法

    问题解决.

  4. [ZJOI2009] 硬币游戏(找规律)

    题目 洛谷传送门 题解 把1/21/21/2转化成0/10/10/1,所以直接可以异或. 对于长度为nnn的0/10/10/1数列,发现每变换2k(k>1)2^k(k>1)2k(k> ...

  5. MD5加密的引用

    使用MD5 加密时 需要在后台代码中添加using System.Security.Cryptography; 引用 //MD5加密密码 byte[] a = MD5.Create().Compute ...

  6. PostgreSQL 配置参数

    一.配置参数所在文件.类型与查看方式 1.配置参数所在文件 postgresql.conf 2.配置参数类型 1)internal只读参数 这些参数不配置在postgresql.conf中,他们由po ...

  7. Ubuntu18.04开机动画(bootsplash)安装

    一.搜索喜欢的主题 1.通过软件源搜索,这个比较简单但是没有太喜欢的.-----------------------------------------------------------pipci@ ...

  8. 递归函数返回值 undefined

    getItem(obj, arr, index) { if (arr.length - 1 !== index) { const tempObj = obj[arr[index]]; this.get ...

  9. python循环导入的问题

    1.问题 循环导入,代码如下: from c import c def b(): print('b') b.py from b import b def a(): # from b import b ...

  10. polyfit 多项式曲线拟合matlab

    polyfit 多项式曲线拟合 全页折叠 语法 p = polyfit(x,y,n) [p,S] = polyfit(x,y,n) [p,S,mu] = polyfit(x,y,n)   说明 示例 ...