如何在 Express 中使用 HTML 作为视图引擎? [英] How do I use HTML as the view engine in Express?

查看:26
本文介绍了如何在 Express 中使用 HTML 作为视图引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从种子中尝试了这个简单的更改并创建了相应的 .html 文件(例如 index.html).

I tried this simple change from the seed and created the corresponding .html files (e.g. index.html).

//app.set('view engine', 'jade');
app.set('view engine', 'html');

并且这个文件保持不变:

and this file remained the same:

exports.index = function(req, res){
  res.render('index');
};

但是在运行时我得到

500 错误:找不到模块html"

500 Error: Cannot find module 'html'

我唯一的选择是使用 'ejs' 吗?我的意图是将纯 HTML 与 AngularJS 结合使用.

Is my only option to use 'ejs'? My intent was to use plain HTML in conjuction with AngularJS.

推荐答案

另一个链接中的答案会起作用,但是要提供 HTML,根本不需要使用视图引擎,除非您想设置时髦的路由.相反,只需使用静态中间件:

The answers at the other link will work, but to serve out HTML, there is no need to use a view engine at all, unless you want to set up funky routing. Instead, just use the static middleware:

app.use(express.static(__dirname + '/public'));

这篇关于如何在 Express 中使用 HTML 作为视图引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆