node.js - What does this line in NodeJs mean? -


i'm wondering these require lines in nodejs mean.

 var debug = require('debug')('morgan')  var deprecate = require('depd')('morgan') 

i'm going through index.js of morgan package in nodejs. require has 1 parameter (package).

require returns ever defined in package. in cases above functions , second parameter calling function. if break out this:

var debugfunctionfactory = require('debug'); var debug = debugfunctionfactory('morgan'); debug('this test debug command'); 

the implementation easy if module in question returns function. , in case of debug , deprecate returns function returns function:

// module code: module.export = function(customname) {   return function(message) {     console.log(customname + ': ' + message);   }; };  // code: var foo = require('module'); // => function var bar = foo('foobar');     // => function bar('baz');                  // "foobar: baz"  // more concisely: var foo = require('module')('foobar');  // => function foo('baz');                             // "foobar: baz" 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -