0

I was doing a nodejs based project using express and when I was adding partials to the app.js file. I got a type error: TypeError: hbs is not a function. I installed npm express-handlebars module. then also showing error again. how to fix it. i also add this code: 'var hbs=require('express-handlebars');'https://i.stack.imgur.com/4hMtT.png

this is my code:

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.engine('hbs', hbs({extname: 'hbs', defualtLayout : 'layout' , layoutsDir: __dirname + '/views/layouts',partialsDir:__dirname+'/views/partials/'}));
lkatiforis
  • 5,703
  • 2
  • 16
  • 35

2 Answers2

0

Looking at the documentation, it doesn't look that you are initializing it in the right way cf.https://www.npmjs.com/package/express-handlebars

Stefano Nepa
  • 491
  • 1
  • 6
  • 13
0

I had the same problem.

Try this:

change hbs({extname: to hbs.engine({extname:

Change this

app.engine('hbs', hbs({extname: 'hbs', defualtLayout : 'layout' , layoutsDir: __dirname + '/views/layouts',partialsDir:__dirname+'/views/partials/'}));

To this:

app.engine('hbs', hbs.engine({extname: 'hbs', defualtLayout : 'layout' , layoutsDir: __dirname + '/views/layouts',partialsDir:__dirname+'/views/partials/'}));
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Sheheem
  • 1
  • 1