Reputation: 511
Learning express in the meantime I am unable to solve this error which says Failed to lookup view "index" in views directory while my folder structure looks like this
I tried setting the path nothing works
const pathDirectory = path.join(__dirname, '../public')
const viewsPath = path.join(__dirname, '../templates/views')
const partialsPath = path.join(__dirname, '../templates/partials')
app.set('views', path.join(__dirname, viewsPath));
hbs.registerPartials(partialsPath)
app.use(express.static(pathDirectory))
The page of index.hbs should be displayed
Upvotes: 1
Views: 1388
Reputation: 1
Simply copy this and try
const partialsPath = path.join(__dirname , "../templates/partials");
// to set the view engine
app.set("view engine","hbs");
app.set('views', path.join(__dirname , '../templates/views'));
hbs.registerPartials(partialsPath);
Upvotes: 0
Reputation: 11
Simply cut your views folder and paste it inside the src.
You can also write
app.set('views', '../templates/views')
Upvotes: 1
Reputation: 21
While you run it on the terminal change your directory to webserver, then run the app.js file using
node src/app.js
I tried this and it worked for me.
Upvotes: 0
Reputation: 1
instead of:
app.set('views', path.join(__dirname, viewsPath));
try:
app.set('views','viewsPath');
Upvotes: 0
Reputation: 61
Try including
app.set('view engine', 'hbs')
after express.static
method.
That would help.
Upvotes: 1