I am going to show my code here: It is a very simple one to just display Either Weekday or Weekend. Installed EJS package from NPM installer
This is list.ejs (inside the views folder)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>T Do List</title>
<script src="app.js"></script>
</head>
<body>
<!-- The EJS is represented by <%= EJS =%> -->
<h1>It is a <%= kindOfDay =%> !</h1> <!-- Corrected -->
</body>
</html>
This is the app.js
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.set('view engine','ejs'); //for EJS
app.get("/", function(req, res){
var today = new Date();
var currentDay = today.getDay();
var day = "";
if(currentDay === 6 || currentDay === 0) // Sunday - Saturday : 0:6
{
day = "weekend";
// list has to exist in views folder || EJS keyword has to match the {key: value} pair
}
else {
day = "weekday";
}
res.render("list", {kindOfDay: day});
});
app.listen(3000, function(){
console.log("Server running at port 3000");
})
This is the index.html file
And this is the error I am getting :
SyntaxError: Unexpected token ')' in ..\todoList-v1\views\list.ejs while compiling ejs
If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
Or, if you meant to create an async function, pass `async: true` as an option.
at new Function (<anonymous>)
at Template.compile (..\todoList-v1\node_modules\ejs\lib\ejs.js:662:12)
Any help would be appreciated: Thank you