maxilaxen
maxilaxen

Reputation: 55

express-handlebars cant find dir or file

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

Upvotes: 5

Views: 5945

Answers (4)

Raul
Raul

Reputation: 961

Silly mistake, I had written this with a camelcase-

extName: '.hbs'

instead of all lowercase-

extname: '.hbs'

Upvotes: 0

athammer
athammer

Reputation: 169

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

app.engine('.hbs', exphbs({
    extname: '.hbs',
    defaultLayout: null
}));

Upvotes: 6

Aelaf
Aelaf

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

Niklas Wenzel
Niklas Wenzel

Reputation: 918

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

Upvotes: 2

Related Questions