2

I'm unable to find the code of get or post methods. I haven't found them in expressjs lib folder, so it's probably that they are present in one of the js files the Router requires.

var express = require('express');
var router = express.Router();

var Blah = require('../modules/Blah');

router.post('/', function(req, res, next) {
  Blah.foo(req, res);
});

I need it to find out where the next parameter is passed to that callback function above, because it has to be done by ExpressJS framework under the hood.

user107986
  • 1,461
  • 1
  • 17
  • 24

2 Answers2

1

Express uses the methods module to dynamically attach http verbs to the router :

lib/router/index.js :

// create Router#VERB functions

methods.concat('all').forEach(function(method){

  proto[method] = function(path){

    var route = this.route(path)

    route[method].apply(route, slice.call(arguments, 1));

    return this;

  };

});
KeatsPeeks
  • 19,126
  • 5
  • 52
  • 83
1

See the answer by KeatsPeeks for more details. Here are some links to specific parts of the source code that might be helpful:

rsp
  • 107,747
  • 29
  • 201
  • 177
  • Thanks! Even though I have all this now, I was unable to find exact line where the callback method is called from post method (I mean this callback function- `function(req, res, next)` here: `router.post('/', function(req, res, next)`.) – user107986 Nov 24 '15 at 15:12
  • In short, I'd like to see the source of the `next` method (see here: http://stackoverflow.com/questions/8710669/having-a-hard-time-trying-to-understand-next-next-in-express-js ) – user107986 Nov 24 '15 at 15:23