0
votes

I´m getting

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

This is my route file:

var express = require("express");
var app = express();
var router = express.Router();


var ctrlLocations = require('../controllers/locations');
var ctrlReviews = require('../controllers/reviews');

/**Locations*/
/*router.get('/locations', ctrlLocations.locationsListByDistante);
*/

    router.post('/locations', ctrlLocations.locationsCreate);
    router.get('/locations/:locationid', ctrlLocations.locationsReadOne);



module.exports = router;

Error LOG:

Error: Route.get() requires a callback function but got a [object Undefined] at Route.(anonymous function) [as get] (C:\Users\Pai\Desktop\mean\node_modules\express\lib\router\route.js:202:15) at Function.proto.(anonymous function) [as get] (C:\Users\Pai\Desktop\mean\node_modules\express\lib\router\index.js:510:19) at Object. (C:\Users\Pai\Desktop\mean\app_api\routes\index.js:14:12) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object. (C:\Users\Pai\Desktop\mean\app.js:22:17) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3)

1
And what is your question? Is the error message not clear?Felix Kling
When i execute the route /locations this show the error Route.get() requires a callback function but got a [object Undefined]Olympike Soft
I understand that. You already described your situation in the post. But you haven't actually asked a question. "I'm getting this error" is not a question. The error message seems pretty clear to me, so I don't know what else you need from us to fix your problem.Felix Kling
Your require doesn't return a function, it returns an Object (or undefined). try console.logging ctrlReviews and ctrlLocations.. but yea @FelixKling is right.. the error makes it clear.Brandon Pereira
This is the function that i use to return : module.exports.locationsCreate = function(req, res){ sendJsonResponse(res, 200, {"status":"sucess"}); };Olympike Soft

1 Answers

0
votes

In your controller/locations.js file, export locationsCreate module as exports.locationsCreate = function(req,res){//your code here }