错误:模块"html"不提供视图引擎(快速) [英] Error: Module "html" does not provide a view engine (Express)

查看:339
本文介绍了错误:模块"html"不提供视图引擎(快速)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个简单的路由应用程序,但是在呈现页面时我一直在运行int错误.

I'm trying to set up a simple routing app but I keep running int the error when rendering a page.

Error: Module "html" does not provide a view engine.

奇怪的是我已经在我的app.js文件中指定了视图引擎,但是仍然出现错误

What is odd is I've specified the view engine in my app.js file but I'm still getting the error

// app.js

var express = require('express');
var app = express();
var router = express.Router();

// Need to import the route file
var chef = require('./chef');
app.use('/chef', chef);

// Set directory to contain the templates ('views')
app.set('views', __dirname + '/views');

// Set view engine to use
app.set('view engine', 'html');

app.use(function(err, req, res, next) {
  console.error(err.stack);
  res.status(500).send('Something broke!');
});


// chef.js
var express = require('express');
var routes = express.Router();

routes.get('/', (req, res) => {
    //res.send("I'm here!")
    res.render('chef');
});

module.exports = routes;

// views/chef.html
Some HTML file here here ..

在Chef.js文件中,当我只想测试路由是否正常时,我取消注释res.send ...,它将我在这里"发送到DOM.

In the chef.js file when I just want to test if the route is working I uncomment res.send ... which sends "I'm here" to the DOM.

但是,每当我尝试使用res.render渲染chef.html页面时,都会收到上述错误.我觉得很奇怪,因为我已经在app.js中设置了视图引擎.

However whenever I try res.render to render the chef.html page I get the error above. Which I find odd because I've set the view engine in app.js.

有关如何呈现我的HTML文件的建议?

Suggestions on how to render my HTML file?

推荐答案

使用res.sendFile('/fileName.html');代替res.render()

用于发送文件,我们使用了res.sendFile(fullPath),如果您使用的不是HTML语言,则必须使用res.render().

for sending file , we used res.sendFile(fullPath) and if you are using other than HTML language then you should have to use res.render().

res.render()用于ejs, pug等模板.

这篇关于错误:模块"html"不提供视图引擎(快速)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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