Error: .post() requires callback functions but got a [object Undefined] not working

后端 未结 8 1918
执念已碎
执念已碎 2021-02-04 09:35

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         


        
相关标签:
8条回答
  • 2021-02-04 10:15

    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.

    0 讨论(0)
  • 2021-02-04 10:17

    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');

    0 讨论(0)
  • 2021-02-04 10:20

    Instead of this:

    app.post('/user/all',Controller.Create);
    

    You try for:

    app.post('/user/all', function(req, res){
      Controller.Create
    });
    
    0 讨论(0)
  • 2021-02-04 10:25

    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.

    0 讨论(0)
  • 2021-02-04 10:30

    For me it was a simple, stupid typo.

    I had module.export = { instead of module.exports = {

    0 讨论(0)
  • 2021-02-04 10:32

    yes Subburaj is correct, Implement in app.js

    app.post('/sign', function (req, res) {
        LoginController.authenticate
    });
    
    

    this could be solve the problem

    0 讨论(0)
提交回复
热议问题