Node says Jade has no method “renderFile”, why?

后端 未结 3 575
执念已碎
执念已碎 2021-01-04 11:28

I installed jade (npm install jade) and went over to their github page to grab some examples. This is what I wanted to execute:

code.jade:

- var titl         


        
3条回答
  •  旧时难觅i
    2021-01-04 12:19

    It looks like newer versions of Jade use a different API, there is no more 'renderFile' method. Take a look at the 'Public API' section on here: https://github.com/visionmedia/jade

    Something like this is probably what you want. Just remember you only need to read the file once. If you are doing it dynamically, be sure not to read it synchronously.

    var jade = require('jade');
    var fs = require('fs');
    
    var jadetemplate = jade.compile(fs.readFileSync('code.jade', 'utf8'));
    
    var html = jadetemplate({
      users: {
        tj: { age: 23, email: 'tj@vision-media.ca', isA: 'human' },
        tobi: { age: 1, email: 'tobi@is-amazing.com', isA: 'ferret' }
      }
    });
    
    console.log(html);
    

    Update

    This answer was valid when it was written, however renderFile was added back in several months later in 92c314, so it may be used now.

提交回复
热议问题