What does double parentheses mean in a require

express, node.js

Solution

This is a pattern in which the `module.exports` of the module you are requiring is set to a function. Requiring that module returns a function, and the parentheses after the require evaluates the function with an argument.

In your example above, your `./routes/index.js` file would look something like the following:

module.exports = function(app) {
  app.get('/', function(req, res) {

  });
  // ...
};

This pattern is often used to pass variables to modules, as can bee seen above with the `app` variable.

Problem

I know what this require statement does. ``` var express = require('express'); var app = express(); ``` But sometimes i have seen two parentheses after the require. ``` var routes = require('./routes')(app); ``` Q) What does this mean, and how does it work?

Original source

Related problems