Unity Hour
Unity Hour

Reputation: 570

Express rendering templates not working inside the sub folder of views?

Here is the picture of my project structure. enter image description here

I am trying to render the add.handlebars when the user visit the route /ideas/me .Here is my code.

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

I understand this is really silly question but when I visit that route it gives Error: Failed to lookup view "ideas/add" in views directory "D:\@Mock Up Sites\vidjot\views".I can fix this easily by telling the template engines to look in all the subfolders of views. But Why this is not working. I am heck sure the directory is correct.

Upvotes: 0

Views: 665

Answers (1)

Saurabh Mistry
Saurabh Mistry

Reputation: 13669

add following line in your app.js

 app.set('views', path.join(__dirname, 'views/'));

Upvotes: 1

Related Questions