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?
Asked
Active
Viewed 1.5k times
3 Answers
28
Problem
Your 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

EJoshuaS - Stand with Ukraine
- 11,977
- 56
- 49
- 78

Salvino D'sa
- 4,018
- 1
- 7
- 19
-
Thank so mutch you're awesome! – Marilia Soares Nov 15 '21 at 13:55
-
Cheers from some months later, presumably following the same tutorial as OP. =) – pdm Feb 07 '22 at 15:46
8
Insert .engine
after handlebars, look:
app.engine('handlebars', handlebars.engine({ defaultLayout: 'main' }));

Tyler2P
- 2,324
- 26
- 22
- 31

Gabriel Carvalho
- 79
- 1
- 5
1
const { engine } = require("express-handlebars");
app.engine( "hbs", engine({ extname: "hbs", defaultLayout: false, layoutsDir: "views/layouts/", }) );

Parthik Pethani
- 11
- 1
-
Welcome to SO. Please write the necessary details in your answer. Code-only answers are not helpful for readers. Please read this https://stackoverflow.com/help/how-to-answer – Muhammad Tariq Apr 02 '22 at 02:16
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 02 '22 at 02:16