coiso
coiso

Reputation: 7479

how to call a controller with express routes and include a defined parameter

//in routes.js (a rough attempt of what I want)

app.get('/test', myCtrl.test(req, res, next, 'type1'));

//in myCtrl.js

exports.test = function(req, res, next, type){
    res.jsonp(type);
};

Like this it gives an error: ReferenceError: req is not defined

Upvotes: 1

Views: 2178

Answers (1)

tymeJV
tymeJV

Reputation: 104775

Wrap that in an anonymous function else it will exec right away:

app.get('/test', function(req, res) {
    myCtrl.test(req, res, next, 'type1');
})

Upvotes: 2

Related Questions