【发布时间】:2022-01-18 00:04:45
【问题描述】:
我是 node.js 的新手,我使用模板引擎 express-handlebar,但我遇到的问题是:**TypeError:handlebars is not a function at Object. ** 。我有很多搜索,但没有任何要修复的答案。我的代码如下:
const morgan = require('morgan');
const handlebars = require('express-handlebars');
const app=express();
const port =3000;
// hTTP logger
app.use(morgan('combined'));
//templace engie
app.engine('handlebars',handlebars());
app.set('view engine','handlebars');
app.get('/',(req,res)=> {
return res.send('hello world');
});
app.listen(port,()=>console.log(`Example app listening at http://localhost:${port}`));````
【问题讨论】:
-
你使用什么版本的
express-handlebars? -
是6.0.2版
-
app.engine('handlebars',handlebars());必须是app.engine('handlebars',handlebars.engine());
标签: node.js express handlebars.js