5

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'

server.js file

ive used

npm i express --save, npm i express-handlebars --save in powershell

maxilaxen
  • 55
  • 1
  • 3

4 Answers4

6

You can also add defaultLayout: null. So for example ...

app.engine('.hbs', exphbs({
    extname: '.hbs',
    defaultLayout: null
}));
athammer
  • 159
  • 1
  • 14
2

Your folder is called layout, but the code is looking for layouts.

Niklas Wenzel
  • 888
  • 7
  • 6
0
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

Aelaf
  • 118
  • 1
  • 11
0

Silly mistake, I had written this with a camelcase-

extName: '.hbs'

instead of all lowercase-

extname: '.hbs'
Raul
  • 800
  • 1
  • 7
  • 22