1

I am fairly new to javascript and am trying to make a simple login restful api with the passport middleware. I know that when i do require('xxxxx'); I am bringing a module in for use.

I found some code online and it has this line "require('./config/passport')(passport);"

I am wondering what it does and how this line differs from just doing "require(passport);"?

Any help would be appreciated.

www.
  • 33
  • 3
  • ./config/passport is something in your local file structure. Look at what is does. It clearly returns a function that expects passport as an argument. – lintmouse Dec 10 '16 at 07:11

1 Answers1

9

You can pass parameters when requiring modules in node.js. Simplified example:

my-console.js

function myConsole(message) {
    console.log(message);
}

module.exports = myConsole;

some-other-file.js

require('./my-console.js')('hey there!');

The above line will require my-console.js, pass the 'hey there' string and execute myConsole function which takes 'hey there' as it's parameter.

borislemke
  • 8,446
  • 5
  • 41
  • 54
  • thanks so much!, this answers a ton fo questions that i had about the example code that i found online – www. Dec 11 '16 at 05:10