N
N
Nwton2017-07-11 13:46:04
Node.js
Nwton, 2017-07-11 13:46:04

What for at exports function to nest in function in this case?

In one module I found this code:

module.exports.authenticate = function(){
  return function(req, res, next){ ... };
}

Why it can't be done like this and why it doesn't work like this:
module.exports.authenticate = function(req, res, next){ ... };

All code in gh

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
g00dv1n, 2017-07-11
@Nwton

Apparently the author was so comfortable. These are middlewares. In the first case, to pass it where as a parameter, you need to call authenticate (), and in the second, just authenticate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question