Reputation: 55
okey so im trying to get handlebars to workand so ive been following this youtube guide: https://www.youtube.com/watch?v=SfQFoMOd_ng
and my problem is that the code on row 15 gets an error:
Error: ENOENT: no such file or directory, open 'C:\Users\9826skma\Desktop\Lol stats\playground\test handlebars\views\layouts\main.handlebars'
ive used
npm i express --save, npm i express-handlebars --save in powershell
Upvotes: 5
Views: 5945
Reputation: 961
Silly mistake, I had written this with a camelcase-
extName: '.hbs'
instead of all lowercase-
extname: '.hbs'
Upvotes: 0
Reputation: 169
You can also add defaultLayout: null. So for example ...
app.engine('.hbs', exphbs({
extname: '.hbs',
defaultLayout: null
}));
Upvotes: 6
Reputation: 118
app.engine('.hbs', exphbs({
extname: '.hbs',
defaultLayout: 'main',
partialsDir: path.join(__dirname, 'views/partials'),
layoutsDir: path.join(__dirname, 'views/layouts')
}));
app.set('view engine', '.hbs');
app.set('views',path.join(__dirname,'views'));
tried the above code and worked smoothly
Upvotes: 0
Reputation: 918
Your folder is called layout
, but the code is looking for layouts
.
Upvotes: 2