Using Middleware in node.js and MVC Routes

Issue

I’m having problems deploying a middleware in the routes of my application, basically, its structure is as shown in the following screenshots.

My middleware:

enter image description here

My Controller:

enter image description here

My routes.js

enter image description here

However, when I try to add the middleware to my route there is an error in the application, I am adding the middleware as follows:
enter image description here

The error returned when starting the application is: Error: Route.get() requires a callback function but got a [object Object]

My application doesn’t have the (req, res) right there after the route declaration, if so, I would just add the middleware first, however, see that my application calls the list method inside the Class Unit directly in the route declaration. How do I increment Middleware there?

Thanks

Solution

You missed exporting middleware function.

Answered By – Abbas Moharami

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published