express-handlebars ERROR

設定 view engine ERROR

express-handlebars@6.0.6 在設定 view engine 出現 error message

app.engine('hbs', exphbs({ defaultLayout: 'main', extname: '.hbs' }))
TypeError: exphbs is not a function

解決辦法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const express = require('express');
const exphbs = require('express-handlebars');

const app = express();
const PORT = 3000;

app.engine('hbs', exphbs.engine({ defaultLayout: 'main', extname: '.hbs' }));
app.set('view engine', 'hbs');

app.get('/', (req, res) => {
res.send(`Hello, World`);
});

app.listen(PORT, () => {
console.log(`Example app listening on http://localhost:${PORT}`);
});