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

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

提交回复
热议问题