I have searching for solutions but nothing working. I installed ejs extention on vs code and also dependency. added *ejs and html in setting and tried several solution on StackOverFlow. The answer should come as Its a Weekend or Weekday but <%KindOfDay%> EJS not working.
/view/list.ejs code is:
<body>
<h1>Its a <%KindOfDay%> </h1>
</body>
and app.js code is:
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.set('views', path(__dirname, 'views'));
app.set('view engine', 'ejs');
app.get("/", (req, res) => {
var today = new Date();
var currentDate = today.getDate();
var day = "";
if (currentDate == 6 || currentDate == 0) {
day = "Weekend";
} else {
day = "Weekday";
}
res.render("list", { KindOfDay: day });
console.log(day);
});
app.listen(3000, () => {
console.log("Server Running");
})
I am providing screenshots and marked in red.
>Solution :
You are wrong tag to display an output. To display output write like this
<%= KindOfDay %>
The one you are using is 'Scriptlet' tag, for control-flow, no output. It is used with loops and if else statements etc.