'TypeError: handlebars is not a function
i have made the handlebars template config on my index.js file, but when i try to run my code with nodemon he returns me this error. anyone can help?
Solution 1:[1]
Problem
You initialization of engine on line 8 is wrong.
Solution
Please change it to app.engine('handlebars', engine());. Check the snippet below.
Implementation
const express = require('express');
const { engine } = require ('express-handlebars');
const app = express();
app.engine('handlebars', engine());
app.set('view engine', 'handlebars');
app.set("views", "./views");
app.get('/', (req, res) => {
res.render('home');
});
app.listen(3000);
Reference
Solution 2:[2]
const { engine } = require("express-handlebars");
app.engine( "hbs", engine({ extname: "hbs", defaultLayout: false, layoutsDir: "views/layouts/", }) );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Parthik Pethani |
