我安装了jade(npm install jam)并转到他们的github页面来获取一些示例。这就是我想要执行的:
代码.jade:
- var title = "Things"
h1= title
ul#users
- each user, name in users
- if (user.isA == "ferret")
li(class: 'user-' + name) #{name} is just a ferret
- else
li(class: 'user-' + name) #{name} #{user.email}
代码.js:
var jade = require('jade');
var options = {
locals: {
users: {
tj: { age: 23, email: 'tj@vision-media.ca', isA: 'human' },
tobi: { age: 1, email: 'tobi@is-amazing.com', isA: 'ferret' }
}
}
};
console.log(jade)
jade.renderFile('code.jade', options, function(err, html){
if (err) throw err;
console.log(html);
});
我将这些文件保存在他们自己的文件夹中,cd 到那里并执行“node code.js”。但是,node 抛出一个错误,说 Jade 没有方法“renderFile”!你能告诉我我做错了什么,我应该怎么做才能解决它?
完整的错误信息:
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object #<Object> has no method 'renderFile'
at Object.<anonymous> (/home/yann/javascript/jade/code.js:18:6)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array.<anonymous> (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)