Skip to content
Advertisement

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:

JavaScript

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

JavaScript

ProgettoRouting.js

JavaScript

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement