there are several issues with the same theme, but I could not solve my problem.
Error: Route.post() requires callback functions but got a [object Undefined]
at R
You want to be sure to check that your spellings are correct for the export and the import. Also make sure your middleware are properly exported and imported.
From the code you are sharing, you should export each middleware individually as
exports.Create
, exports.Update
etc. Setting up your export this way will make it possible to access it the way you are currently accessing it view the Controller
variable in your rutas.js
file.
Always ensure the export name is the same as the import name
//Function Exported
exports.isAuthenticatedUser = catchAsyncErrors(async(req, res, next) => {
}
//Function Imported
const {isAuthenticatedUser} = require('../middlewares/auth');
Instead of this:
app.post('/user/all',Controller.Create);
You try for:
app.post('/user/all', function(req, res){
Controller.Create
});
In my case it was because I had a misspelling between the router and controller file. Check both so that they match, the error .POST() requires callback functions but got a [object Undefined]
has nothing to do with the real problem.
For me it was a simple, stupid typo.
I had module.export = {
instead of module.exports = {
yes Subburaj is correct, Implement in app.js
app.post('/sign', function (req, res) {
LoginController.authenticate
});
this could be solve the problem