Error is "app.engine("handlebars", exphbs()); ‘TypeError: exphbs is not a function
at Object. ‘"
const express = require('express')
const exphbs = require("express-handlebars");
const path = require("path");
const app = express()
const port = 3000
app.engine("handlebars", exphbs());
app.set("view engine", "handlebars");
2
Answers
I think its possible that the exphbs function is not properly installed or imported:
Import it with:
If that’s not the case, and you have it installed and imported correctly. Then see if updating to the latest version fixes the issue:
EDIT: Now that I think about it, you need to call the engine() function on exphbs to get the actual function that you can use to register the handlebars templating engine with your Express app.
The correct code should be:
exphbs
isn’t a function, it is an object of stuff exported by handlebars (see the documentation). The function you want to use isexphbs.engine()
like this:Alternatively, you can destructure the object and take out
engine
directly: