Here is my code,
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.set("view engine", "ejs");
app.get("/", function(req, res){
var today = new Date();
var currDay = today.getDay();
var day = "";
if(currDay == 0){
day = "Sunday";
}
else if(currDay == 1){
day = "Monday";
}
else if(currDay == 2){
day = "Tuesday";
}
else if(currDay == 3){
day = "Wednesday";
}
else if(currDay == 4){
day = "Thrusday";
}
res.render('list', {todayDay : day});
});
app.listen(4000, function(){
console.log("Hey, you are in port 4000");
});
I am watching angela yu's web dev course while I got stuck in the phase where the error is this.
Error: Failed to lookup view "list" in views directory "C:\Users\ASUS\Dropbox\PC\Desktop\To-do\views" at Function.render (C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\application.js:597:17) at ServerResponse.render (C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\response.js:1039:7) at C:\Users\ASUS\Dropbox\PC\Desktop\To-do\app.js:33:9 at Layer.handle [as handle_request] (C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\router\layer.js:95:5) at next (C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\router\route.js:144:13) at Route.dispatch (C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\router\route.js:114:3) at Layer.handle [as handle_request] (C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\router\layer.js:95:5) at C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\router\index.js:284:15 at Function.process_params (C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\router\index.js:346:12) at next (C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\router\index.js:280:10)
Please if anybody can help me out.?
the list file must be in a directory called views
and you need to add it to the app
const path = require('path')
app.set('views', path.join(__dirname, 'views'));
this error is telling that it cannot find the filed called list