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
随机推荐
- WCF之MSMQ消息队列
一.MSMQ简介 MSMQ(微软消息队列)是Windows操作系统中消息应用程序的基础,是用于创建分布式.松散连接的消息通讯应用程序的开发工具. MSMQ与XML Web Services和.Net ...
- tomcat实现文件上传下载
实现下载 修改server.xml修改web.xml 实现上传 实现客户端的上传post请求代码实现 实现服务端的处理 小结 实现下载 实现下载需要 - 修改Tomcat中的 ...
- Python 高级
GIL面试题如下 描述Python GIL的概念, 以及它对python多线程的影响?编写一个多线程抓取网页的程序,并阐明多线程抓取程序是否可比单线程性能有提升,并解释原因. Guido的声明:ht ...
- TinyMCE 工具栏配置
plugins: { type: [String, Array], default: 'lists image media wordcount advlist bbcode code charmap ...
- Windows 创建Raid
Windows 常见raid有0.1和5,以下操作在虚拟机下模拟,学会这招在自己电脑做个raid也未尝不可啊~ 一.RAID 0 创建: 添加两块硬盘,联机并初始化(2T以下选MBR,以上选GPT) ...
- 【原创】go语言学习(二十二)网络编程
目录 TCP/IP协议介绍 GO快速实现TCP服务端 GO快速实现TCP客户端 UDP协议介绍 UDP编程实例 TCP/IP协议介绍 1.互联网起源 A. 起源于美国五角大楼,它的前身是美国国防部高级 ...
- ACwing_789. 数的范围
算法竞赛进阶指南上说据说只有10%的程序员能写对二分,而我这种蒟蒻..所以虽然这是一道非常基础的二分,但我觉得对我来说还是有必要写一篇博客来总结一下,也在写的过程中检验一下自己. 一开始看到这道题我还 ...
- 1823:【00NOIP提高组】方格取数
#include<bits/stdc++.h> using namespace std; ][]; ][][][]; inline int max(int x,int y) { retur ...
- Python geometry_msgs.msg.PoseStamped() Examples
https://www.programcreek.com/python/example/70252/geometry_msgs.msg.PoseStampedhttps://programtalk.c ...
- nginx做反向代理时出现302错误
现象:nginx在使用非80端口做反向代理时,浏览器访问发现返回302错误 详细现象如下: 浏览器请求登录页: 输入账号密码点击登录: 很明显登录后跳转的地址少了端口号. 原因:proxy.conf文 ...