Error: Route.post() requires a callback function but got a [object Undefined]

If you use the NodeJS Express server, you have just created a new route with the code like this

router.post('/my_new_action', authenticationMiddleware, myController.myNewFunction);

and created a new function to handle the request, like

async function myNewFunction(req, res) {
...
}

and get the error message:

…/node_modules/express/lib/router/route.js:211
throw new Error(msg);
^

Error: Route.post() requires a callback function but got a [object Undefined]

make sure you export the new function in the controller.

module.exports = {
  myFirstFunction,
  myNewFunction
};

Leave a comment

Your email address will not be published. Required fields are marked *