【发布时间】:2023-04-09 19:45:01
【问题描述】:
我尝试在 Express 中使用车把模板。我收到此错误消息:
TypeError: this.engine 不是一个函数 在 View.render (/home/ubuntu/workspace/node_modules/express/lib/view.js:128:8) ...
使用此代码:
'use strict';
var express = require('express');
var expressHandlebars = require('express-handlebars');
var app = express();
app.engine('handlebars', expressHandlebars({defaultLayout: 'layout'}));
app.set('view engine', 'html');
app.use(express.static('views'));
app.route('/single/:id')
.get(function (req, res) {
res.render(process.cwd() + `/public/single-poll`, {
id: req.params.id
});
});
app.listen(process.env.PORT, function () {
console.log('Node.js listening on port ' + process.env.PORT + '...');
});
当我用 sendFile() 替换 render() 函数时工作正常。我知道Express js render : TypeError: this.engine is not a function 和Express js render error this.engine is not a function 和TypeError: this.engine is not a function when trying to use Moustache in Express JS,但它们对我没有帮助。
可能是什么问题?
【问题讨论】:
标签: node.js express handlebars.js render