//jshint esversion:6
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use("view-engine", "ejs");
app.get("/", function(req, res){
var today = new Date();
var currentDay = today.getDay();
var day = "";
if (currentDay === 6 || currentDay === 0) {
day = "Weekend";
}else {
day = "weekday";
}
res.render("list" , {kindofDay: day});
});
app.listen(3000, function(){
console.log("Server started on port 3000");
});
i can't see where i have gone wrong. Can anybody see? whenever i run this app.js showing that router.use() requires a middleware function but got a ' + gettype(fn) this error.
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>To Do List</title>
</head>
<body>
<h1>It's a <%= kindofDay %></h1>
</body>
</html>
This is my list.ejs file..
app.use([path,] callback [, callback...]) -> This code is what you use when you want a specific callback function to run at a specific path. This is called a middleware.
app.set(name, value) -> This code is what you use when you want assign a value to some variable. You can uyse any name, but certain names can be used to configure the behavior of the server.
One of these names is view engine (notice there is no hyphen). It will set the template engine to use.
If your aim is to set ejs as your template engine, just do app.set("view engine", "ejs");