Search code examples
node.jsexpresswebexpress-handlebarshbs

TypeError: hbs is not a function


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.sstatic.net/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/'}));

Solution

  • 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