[英]How to change template engine of node.js project?
I have this node.js project, it uses jade template.我有这个node.js 项目,它使用 jade 模板。 But I need to use simple html pages.但我需要使用简单的 html 页面。 Guideline needed for safe transformation.安全转型所需的指南。
I need to use complete .html pages like index.html, login.html.我需要使用完整的 .html 页面,如 index.html、login.html。 Without any template engine to show at routes like localhost:3000 and localhost:3000/login.html.没有任何模板引擎显示在诸如 localhost:3000 和 localhost:3000/login.html 之类的路由上。 Which should work with full functionality.哪个应该具有完整的功能。
You can change it in config/express.js
:您可以在config/express.js
更改它:
app.set('view engine', 'jade')
For example, if you want to use Handlebars , then remove "jade": "latest",
in packages.json
and add "handlebars": "latest"
.例如,如果您想使用Handlebars ,则在packages.json
删除"jade": "latest",
并添加"handlebars": "latest"
。 Then run npm install
and edit config/express.js
:然后运行npm install
并编辑config/express.js
:
app.set('view engine', 'handlebars')
Express server static html files by default.默认情况下 Express 服务器静态 html 文件。
Place your html files in /public folder:将您的 html 文件放在/public文件夹中:
...
/public
index.html
login.html
...
and go localhost:3000/ or localhost:3000/login.html but this is static files and then the application logic should be on the front-end.然后转到 localhost:3000/ 或 localhost:3000/login.html 但这是静态文件,然后应用程序逻辑应该在前端。 For example using angular or backbone.例如使用角度或主干。
app.get('/any_location', function(req, res){
res.sendFile('Location_to_htmlFile');
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.