Reputation: 1087
I am trying to create a route in my app and access the controller method.
I have something like these in my route.js
var express = require('express');
var route = express.Router();
var testController = require('../controllers/testController');
//express middleware
route.use(function(req, res, next){
next();
})
//getting testController.getAll is not a function error
route.get('/getall', testController.getAll());
//Route.get() requires callback functions but got a [object Undefined] error
route.get('/getall', testController.getAll);
module.exports = route;
My testController
var testController = function(){
function getAll (req, res) {
res.send('123456')
}
return {
getAll: getAll
}
}
module.exports = testController;
I am not sure how to make sure 123456
get returned to the request. Can anyone help me about it? Thanks a lot!
Upvotes: 1
Views: 54