Directory Search Error with Express Handlebars

I am following the basic layout of the application you get from Express Generator and trying to configure it for Handlebars.

Excerpt:

var exphbs = require('express-handlebars'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views/')); app.engine('handlebars', exphbs({defaultLayout: 'main'})); app.set('view engine', 'handlebars'); 

Everything is fine until I try to change the extension for Handlebars to .hbs as follows:

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

(and of course rename files).

This leads to:

Error: Could not view "error" in the submissions directory

I looked at function ExpressHandlebars(config) in the source express-handlebars.js and tried to set extname correctly.

What am I doing wrong?

+6
source share
1 answer

Somewhat intuitively, setting the extension name is not enough.

Required Setup:

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

Source: https://habr.com/ru/post/976946/


All Articles