0
ERROR:

Error: Failed to lookup view "home" in views directory "C:\Users\Lenovo T460p\Desktop\Node-tut\MainPage\mernbackend\src\views"
    at Function.render (C:\Users\Lenovo T460p\Desktop\Node-tut\MainPage\mernbackend\node_modules\express\lib\application.js:597:17)
    at ServerResponse.render (C:\Users\Lenovo T460p\Desktop\Node-

app.js

so i will try my best and cannot resolve this directory path error.
i will add the path and directory in the views/home but cannot resolve it .

first i get the heros.hbs error then i will add the files or heros.hbs and after it the home directory error will be shown
//define the path so the directory access the path directly

//serving public file
const public_path = path.join(__dirname,"../public");
app.use(express.static(public_path));



//this required before view engine setup
hbs.registerPartials(__dirname + '/views/partials');

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');


app.get("/about",(req,res)=>{
    res.render("about",{name:"Hammad Ahsan",img:"/img/2.png"})
});


app.get("/contact",(req,res)=>{
    res.render("contact")
});
//lets render the register form or access it on the localhost
app.get("/register",(req,res)=>{
    res.render("register")
});

// and all the logout,login and further the project code below 

app.listen(port,()=>{
    console.log(`the server is running port no ${port}`);
});

//i don't know why i cannot the further code it asked me that u cannot add the enough details

// create Collection

const Register= new mongoose.model("Register",userSchema);

module.exports = Register;

this is the error I couldn't resolve it .I will add the view/home directory in the app.js

I want to resolve this error and continue my working

0 Answers0