5

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"

1

2 Answers 2

7

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
3
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.