我正在尝试使用jade和node.js在目录中列出一个文件,但我不确定下面是否是正确的做法,因为我收到一个类型错误,上面写着
Cannot read property 'length' of undefined
任何提示将不胜感激
h1 Your tasks
p
// list all the file
ul
for file in files
li
p= file
node.js 代码
app.get('/tasks', function(req, res){
fs.readdir('tasks/index', function(err, data){
res.render('tasks/index', {"files": data});
});
});
更新
app.get('/tasks', function(req, res){
fs.readdir('tasks', function(err, data){
res.render('tasks/index', {"files": data});
});
});
错误
500 TypeError: /path/views/tasks/index.jade:7 5| // list all the file 6| ul > 7| each file in files 8| li 9| p= file 10| Cannot read property 'length' of undefined
5| // list all the file
6| ul
> 7| each file in files
8| li
9| p= file
10|
Cannot read property 'length' of undefined