Error: No default engine was specified and no extension was provided

前端 未结 14 2583
别跟我提以往
别跟我提以往 2020-11-29 18:13

I am working through setting up a http server using node.js and engine. However, I keep running into issues that I have little information on how to resolve I would apprecia

14条回答
  •  死守一世寂寞
    2020-11-29 18:45

    Comment out the res.render lines in your code and add in next(err); instead. If you're not using a view engine, the res.render stuff will throw an error.

    Sorry, you'll have to comment out this line as well:

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

    My solution would result in not using a view engine though. You don't need a view engine, but if that's the goal, try this:

    app.set('views', path.join(__dirname, 'views'));
    app.set('view engine', 'jade');
    //swap jade for ejs etc
    

    You'll need the res.render lines when using a view engine as well. Something like this:

    // error handlers
    // development error handler
    // will print stacktrace
    if (app.get('env') === 'development') {
      app.use(function(err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
        message: err.message,
        error: err
        });
      });
    }
    // production error handler
    // no stacktraces leaked to user
    app.use(function(err, req, res, next) {
      res.status(err.status || 500);
      next(err);
      res.render('error', {
      message: err.message,
      error: {}
      });
    });
    

提交回复
热议问题