Express和JSHtml生成TypeError

时间:2013-12-08 17:58:29

标签: node.js express jshtml

我开始使用Express学习Node.JS以进行Web应用程序。最初看Jade,我想要更多...... HTML-y。所以,我看了jshtml。我用这个来生成样板应用程序:

$ express --jshtml -c less

这产生了一些看起来很正常的东西。但是,当我实际运行它时,我试图查看索引页面:

TypeError: Property 'engine' of object #<View> is not a function
    at View.render (/home/earlz/projects/extest/node_modules/express/lib/view.js:76:8)
    at Function.app.render (/home/earlz/projects/extest/node_modules/express/lib/application.js:504:10)
    at ServerResponse.res.render (/home/earlz/projects/extest/node_modules/express/lib/response.js:798:7)
    at exports.index (/home/earlz/projects/extest/routes/index.js:7:7)
    at callbacks (/home/earlz/projects/extest/node_modules/express/lib/router/index.js:164:37)
    at param (/home/earlz/projects/extest/node_modules/express/lib/router/index.js:138:11)
    at pass (/home/earlz/projects/extest/node_modules/express/lib/router/index.js:145:5)
    at Router._dispatch (/home/earlz/projects/extest/node_modules/express/lib/router/index.js:173:5)
    at Object.router (/home/earlz/projects/extest/node_modules/express/lib/router/index.js:33:10)
    at next (/home/earlz/projects/extest/node_modules/express/node_modules/connect/lib/proto.js:193:15)
GET / 500 20ms

我必须安装其他东西吗?或者我如何让它工作?

1 个答案:

答案 0 :(得分:0)

您需要为Express安装jshtml engine并在配置服务器时使用它。

npm install jshtml-express

像这样配置您的服务器;

var jshtml = require('jshtml-express');

app.engine('jshtml', jshtml); 
app.set('view engine', 'jshtml');

希望这会有所帮助。 :)