I need to use "fs" module inside a Jade file. No other JS file.
When I try:
- var js = require('fs')
- var downloadfiles = readdirSync("download")
for f in downloadfiles
url
loc= D + "/download" + f
lastmod= buildDate
changefreq daily
priority 1.0
I got the error "undefined is not a function"
Two problems
You should send the function to the Jade file as an argument rather than trying to require it in Jade ie.
var js = require('fs');
res.render('myjadefile', {fsFunction: fs});
myjadefile.jade
- var downloadfile = fsFunction.readdirSync('download');
for f in downloadfiles
// rest of your code
Also, in line 2 you are calling function "readdirSync" without defining it anywhere. It should be
fs.readdirSync
res.render(index, {data:data,
title:'Jade Require'
require:require})
Now in your jade.
extends layout
!{fs=require('fs')}
body
- var downloadfiles = readdirSync("download")
for f in downloadfiles
url
loc= D + "/download" + f
lastmod= buildDate
changefreq daily
priority 1.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With