Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
i run this code but showing router.use() requires a middleware function but got a ' + gettype(fn) this error

//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..

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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");

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!