如何更改node.js项目的模板引擎?

时间:2014-05-23 07:50:25

标签: node.js express template-engine

我有this node.js项目,它使用jade模板。但我需要使用简单的html页面。安全转型需要准则。

我需要使用像index.html,login.html这样的完整.html页面。没有任何模板引擎可以在localhost:3000和localhost:3000 / login.html等路由中显示。哪个应该可以使用全部功能。

3 个答案:

答案 0 :(得分:5)

您可以在config/express.js

中进行更改
app.set('view engine', 'jade')

例如,如果您要使用Handlebars,请移除"jade": "latest",中的packages.json并添加"handlebars": "latest"。然后运行npm install并修改config/express.js

 app.set('view engine', 'handlebars')

答案 1 :(得分:1)

默认情况下Express服务器静态html文件。

将您的html文件放在 / public 文件夹中:

    ...
    /public
       index.html
       login.html
       ...

并转到localhost:3000 /或localhost:3000 / login.html 但这是静态文件,然后应用程序逻辑应该在前端。例如,使用角度或主干。

答案 2 :(得分:0)

app.get('/any_location', function(req, res){
    res.sendFile('Location_to_htmlFile');
})