I have been writing a code for a to do list, this is the node file:
const express=require("express");
const bodyParser=require("body-parser");
const ejs = require('ejs');
const app=express();
app.set("view engine", 'ejs');
app.get("/", function(req, res){
var today=new Date();
var currentDay=today.getDay();
var days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var day=""
if (currentDay===6||currentDay===0){
res.write("Yay today is a weekend")
day=days[currentDay];
console.log(day)
res.render("list",{kindaDay:day});
res.send();
}
else{
res.write("boo this is a weekday")
day=days[currentDay];
res.render("list",{kindaDay:day});
res.send();
}
})
app.listen(3000, function(){
console.log("connected to port 3000");
})
And this is the EJS file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
</head>
<body>
<h1>It is an amazing day as it is an <%=kindaDay%> </h1>
<script src="" async defer></script>
</body>
</html>
The file gives an error which says "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client" What could possibly be the error?