我需要在Jade文件中使用"fs"模块.没有其他JS文件.
当我尝试:
- var js = require('fs')
- var downloadfiles = readdirSync("download") 
for f in downloadfiles
  url
    loc= D + "/download" + f
    lastmod= buildDate
    changefreq daily
    priority 1.0
Run Code Online (Sandbox Code Playgroud)
我收到错误"undefined is not a function"
两个问题
 
您应该将函数作为参数发送到Jade文件,而不是尝试在Jade中要求它.
var js = require('fs');
res.render('myjadefile', {fsFunction: fs});
Run Code Online (Sandbox Code Playgroud)
myjadefile.jade
- var downloadfile = fsFunction.readdirSync('download');
for f in downloadfiles
   // rest of your code
Run Code Online (Sandbox Code Playgroud)
此外,在第2行中,您调用函数"readdirSync"而不在任何地方定义它.它应该是
fs.readdirSync
Run Code Online (Sandbox Code Playgroud)