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?
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?
You initialization of engine on line 8 is wrong.
Please change it to app.engine('handlebars', engine());. Check the snippet below.
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);
Insert .engine after handlebars, look:
app.engine('handlebars', handlebars.engine({ defaultLayout: 'main' }));
const { engine } = require("express-handlebars");
app.engine( "hbs", engine({ extname: "hbs", defaultLayout: false, layoutsDir: "views/layouts/", }) );