Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.3K
Views
TypeError: exphbs is not a function

I am trying to use the express-handlebars module but have an error. My code:

var exphbs = require('express-handlebars');

app.engine('.hbs', exphbs({ extname: '.hbs', defaultLayout: "main"}));
app.set('view engine', '.hbs');

My error:

"app.engine('.hbs', exphbs({ extname: '.hbs', defaultLayout: "main"}));
                   ^

TypeError: exphbs is not a function"

I can't seem to figure it out why is it not working properly. Any ideas?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You should use "exphbs.engine" instead of "exphbs".

app.engine('.hbs', exphbs.engine({ extname: '.hbs', defaultLayout: "main"}));
over 4 years ago · Santiago Trujillo Report

0

If you want to use express-handlebars with commonJS module you should import it like that:


const express = require('express');
const { engine } = require('express-handlebars');

const app = express();

app.engine('handlebars', engine({ extname: '.hbs', defaultLayout: "main"}));
app.set('view engine', 'handlebars');
app.set("views", "./views");

app.get('/', (req, res) => {
    res.render('home');
});

app.listen(3000);

If you want to go with ES6 module, you can follow the official readme

over 4 years ago · Santiago Trujillo Report

0

You have two options to solve this

1st Method-

In this you just have to update a single word .enigne

Change this:

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

To

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

2nd Method-

In this, you have to update

var exphbs = require('express-handlebars'); 

To

 const { engine } = require('express-handlebars');

And

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

To

app.engine('handlebars', engine({ extname: '.hbs', defaultLayout: "main"}));

Goodluck

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!