Error: Module “html” does not provide a view engine (Express)

送分小仙女□ 提交于 2020-01-24 22:03:25

问题


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.

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 ..

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.

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.

Suggestions on how to render my HTML file?


回答1:


use res.sendFile('/fileName.html'); instead of 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() for template like ejs, pug etc.



来源:https://stackoverflow.com/questions/46848773/error-module-html-does-not-provide-a-view-engine-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!