Node.js报错TypeError: Cannot read property 'isDirectory' of undefined
截图如下:

原因如下:记住"./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的更多相关文章
- Node中使用MySQL报错:TypeError: Cannot read property 'query' of undefined
Node中使用MySQL报错: TypeError: Cannot read property 'query' of undefined at /Users/sipeng/Desktop/彭思/201 ...
- VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法
正常情况下在data里面都有做了定义 在函数里面进行赋值 这时候你运行时会发现,数据可以请求到,但是会报错 TypeError: Cannot set property 'listgroup' of ...
- JS报错:Cannot read property 'type' of undefined
在做图片上传功能的时候,遇到了JS无法识别图片type的问题,在使用过程中是没有问题的,但是不知道为什么浏览器的Console报这个错误: Uncaught TypeError: Cannot rea ...
- 使用webpack命令打包时,报错TypeError: Cannot read property 'presetToOptions' of undefined的解决办法
我只安装了webpack,没有安装webpack-cli,第一次输入webpack打包时,提示 One CLI for webpack must be installed. These are rec ...
- vue表单校验提交报错TypeError: Cannot read property 'validate' of undefined
TypeError: Cannot read property 'validate' of undefined at VueComponent.submitForm (plat_users.html: ...
- vue报错TypeError: Cannot read property 'protocol' of undefined
错误信息如下所示: isURLSameOrigin.js?3934:57 Uncaught (in promise) TypeError: Cannot read property 'protocol ...
- vue报错TypeError: Cannot read property '$createElement' of undefined
报错截图: 这个错误就是路由上的component写成了components
- react报错 TypeError: Cannot read property 'setState' of undefined
代码如下: class test extends Component { constructor(props) { super(props); this.state = { liked: false ...
- 73.node.js开发错误——TypeError: Cannot set property 'XXX' of undefined
转自:https://blog.csdn.net/fd214333890/article/details/53467429
随机推荐
- linux 防火墙 firewall 设置
背景: 机房断电后导致机器关机重启,原先访问的地址访问不了,使用终端能访问到该服务器,服务启起来后,用curl + 地址能访问,但在外部浏览器访问不了该地址: 首先想到了端口限制----防火墙 参考博 ...
- linux基础第四周
天津SEO: 1.统计出/etc/passwd文件中默认shell为非/sbin/nologin的用户个数,并将用户都显示出来 [root@localhost ~]# awk -F: -v i=&qu ...
- 后端token认证模板
1.创建一个视图 from rest_framework import exceptions from app01 import models from rest_framework.authenti ...
- Manthan, Codefest 19
目录 Contest Info Solutions A. XORinacci B. Uniqueness C. Magic Grid D. Restore Permutation E. Let The ...
- javascript 闭包(closure)
<script type="text/javascript"> //闭包(closure):内层函数可以引用存在于包围它的函数内的变量,即使外层函数的执行已经结束 ...
- phpstorm 2019.1 mac
链接:https://pan.baidu.com/s/10x0Oa24aOZHJYCYgUGe8yg 密码:muah 安装完成后, sudo vi /etc/hosts 添加以下内容到hosts 0 ...
- Cubic-bezier 曲线
cubic-bezier又称三次贝塞尔,主要是为animation生成速度曲线函数. cubic-bezier(x1,y1,x2,y2) 此图中: P0:(0,0) P1:(x1,y1) P2:(x2 ...
- 控制器,action, 过滤器, 权限
这个是重点学习对象 控制器 https://www.cnblogs.com/caoyc/p/5671687.html 还有这个 https://www.cnblogs.com/leoo2sk/arc ...
- HttpClient学习(四)—— 关于Http
一.Http状态码 状态码分类 100 ~ 199 信息提示 200 ~ 299 成功 300 ~ 399 重定向 400 ~ 499 客户端错误 500 ~ 599 服务端错误 常见状态码 200 ...
- .NET开发人员的完美.gitignore文件
# Build and Object Folders bin/ obj/ # Nuget packages directory packages/ ## Ignore Visual Studio te ...