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

614
Views
TypeError: Router.use() requires a middleware function but got a string at Function.use

I'm new to Node and ExpressJs development, however, I cannot import a module router created by me as an exercise.

It gives me this error:

TypeError: Router.use () requires a middleware function but got a string
     at Function.use

I have already tried the module.exports solution, but it doesn't work. The initialize function also fails.

Here are the versions I am working with:
Node version: v10.19.0
Express version: 4.17.2

Index.js

    const express = require('express');
const app = express();
const ProgettoRouting = require("./routing/ProgettoRouting");

app.use("view engine","jade");
app.use(express.static("public"));
//Codifica dati json con questo middlware senza uso
//del pacchetto npm Body Parser
app.use(express.json());

//Con questo milldelware Importiamo il Router Dati
//dove risiedono le funzionalità del progetto
app.use('/route', ProgettoRouting);

//app.use(app.ProgettoRouting);
//ProgettoRouting.initialize(app);

app.listen(3000, () => {console.log("Server in ascolto sulla porta 3000")});

ProgettoRouting.js

const express = require('express');
const router = express.Router();


router.post("/",(res,req) => {
    let firstName = req.body.nome;
    let lastName = req.body.cognome;
    let message = {nome: firstName, cognome: lastName};
    res.render("index",message);
});

module.exports = router;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to use

app.set("view engine","jade");

instead of

app.use("view engine","jade");

as you're intending to set the view-engine property to jade, not setting up a middleware.

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!