Sourav Kumar
Sourav Kumar

Reputation: 41

ENOENT when loading Handlebars template

I'm using express framework,

//Handlebars Middleware
app.engine('handlebars', exphbs({
  defaultLayout: 'main'
}));
app.set('views', path.join(__dirname, './views'));
app.set('view engine', 'handlebars');

My directory looks like:

enter image description here

and it gives the below error whenever I try to run.

Error: ENOENT: no such file or directory, 
open 'C:\Users\Sourav\forum\bin\views\layouts\main.handlebars'

Any help is appreciated. It's my first question so, every suggestion regarding question clarity is very much appreciated.

Thanks

Upvotes: 0

Views: 2941

Answers (1)

avin45h
avin45h

Reputation: 46

__dirname in this case is pointing inside bin folder, instead of './views' use '../views'

Upvotes: 1

Related Questions