Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express js retrieve route callback function

Tags:

express

In Express js, I register a route like this:

module.exports = function(app) {

  app.get('/user/new', function(req, res) {
    res.render('user/new', {title: "Register"});
  });
}

How can I retrieve the callback function from that '/user/new' route, meaning to retrieve back the function below:

function(req, res) {
    res.render('user/new', {title: "Register"});
}
like image 939
Khanh Tran Avatar asked Jun 10 '26 02:06

Khanh Tran


1 Answers

Bit of a hack:

var handler = app._router.match('get', '/user/new').callbacks[0];
like image 106
robertklep Avatar answered Jun 11 '26 18:06

robertklep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!