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

后端 未结 8 1919
执念已碎
执念已碎 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:34

    This error usually comes when you mistakenly import functions in the wrong way, or may be a spelling mistake Both the controller and the route are in some trouble.

    I encountered this when I was exporting a function from the controller which was all good.

    exports.addCategory = (req,res) => {}
    

    but when I was importing it in the routes I was doing

    const addCategory = require('../Controllers/Category')
    

    instead

    const {addCategory) = require('../Controllers/Category')
    

    you see that curly braces around addCategory while importing So, I was importing the entire function, which was wrong

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

    You are only missing

    module.exports = app, or whatever you are exporting. This happened to me many times.

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