I am trying to add hbs template in my code but I am getting the errror that Failed to lookup view "index" in views directory
const express = require("express")
const path = require("path")
require("../src/db/conn")
const app = express();
const port = process.env.PORT || 3000;
const static_path = path.join(__dirname, "../public")
app.use(express.static(static_path))
app.set("view engine" , "hbs");
app.get("/" , (req,res)=>{
res.render("index")
})
app.listen(port , ()=>{
console.log("server is listening on port no 3000" )
})
this is my code and also i have created a views folder and a index.hbs file inside that folder
CodePudding user response:
app.set("view engine" , "hbs"); After this line add
app.set("views" , "views");