-1

I'm a complete novice in node.js and just have started working on it. I was following few tutorials online on 'mongoDB' and 'monk' and I came across this syntax var db = require('monk')('localhost:27017/test').

Now, I know we're requiring the 'monk' package and connecting to the specified URL. However, the thing which I'm unable to understand is that how are we passing the URL in the second pair of parenthesis. What exactly does this second pair of parenthesis mean? Is it a function, object, callback function or what?

I looked over on the web for the same but didn't get much help. They've not explained this anywhere. Need some help to understand it.

Kartik Chauhan
  • 2,779
  • 5
  • 28
  • 39

1 Answers1

1

The monk module is exporting a function, and that function is what's returned by the require call, and this syntax is then calling that in one line.

It's just the same as writing:

let Monk = require('monk');
let db = Monk('localhost:27017/test');
Alnitak
  • 334,560
  • 70
  • 407
  • 495