MBehtemam
MBehtemam

Reputation: 7919

Node Require with two Parenthesis

Recently im try to read codes of koajs and find this line of code:

var debug = require('debug')('koa-route');

What this mean ? why use ('debug') and then ('koa-route') ? you can find the code here . and i say that i find this line of code in koa-route middle ware defination

Upvotes: 2

Views: 215

Answers (2)

Trevor Norris
Trevor Norris

Reputation: 21119

The module basically looks something like this:

function toRun() {
  // do stuff
}

module.exports = toRun;

Then your script code does the following:

var ran = require('torun')();

This is a convenient way to expose something most often used, but also usable if you want to expose some methods directly on the exported Function. For example:

function toRun() {
  // do stuff
}

toRun.moreStuff = function() {
  // and again
};

module.exports = toRun;

Then to get access to the additional functions you can just grab the entire thing:

var toRun = require('torun');
var ran = toRun();
var stuff = toRun.moreStuff();

Upvotes: 1

MBehtemam
MBehtemam

Reputation: 7919

According to comment and debug defination require('debug') return a function and ('koa-route') is parameter of this function.

Upvotes: 1

Related Questions