Reputation: 3357
I am new to Javascript and even newer to Node. I am trying to read an express server code and can't figure out following line in my app.js file:
module.require('./auth')(passport);
I know I have a variable that holds passport module in app.js:
var passport = require('passport');
and I also have auth.js in the same directory which exports the following function:
module.exports = function(passport) {
passport.use('local-login', new LocalStrategy({
usernameField: 'email'
}, function(idpEmail, password, done) {
// do email mapping
findEmailFromDummyDb(idpEmail, password,function(err,user){
if(err) {
done(null, false, {
messages: err.toString()
});
} else {
done(null, {
sysEmail: user.sysEmail
});
}
});
}));
However, what does following function actually do?
module.require('./auth')(passport);
Upvotes: 2
Views: 2573
Reputation: 73221
module.require('./auth')
imports a function, then it get's called with passport
as a parameter. It's the same as
const auth = require('./auth');
const passport = require('passport');
auth = auth(passport);
Upvotes: 3
Reputation: 5606
The below returns a javascript function.
module.require('./auth');
You are then immediately calling the function with the passport object as a function argument.
(passport)
Upvotes: 1