Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda