admin管理员组

文章数量:1402807

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 unment 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?

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 unment 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?

Share Improve this question asked Oct 20, 2017 at 12:09 Chef1075Chef1075 2,7249 gold badges43 silver badges57 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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.

本文标签: javascriptError Module quothtmlquot does not provide a view engine (Express)Stack Overflow