In https://github.com/jaredhanson/passport-local/blob/master/lib/index.js there is a construct as below:
/**
* Module dependencies.
*/
var Strategy = require('./strategy');
/**
* Expose `Strategy` directly from package.
*/
exports = module.exports = Strategy;
/**
* Export constructors.
*/
exports.Strategy = Strategy;
It looks like Strategy is exported twice - directly and through the property Strategy - i.e. require('passport-local') and require('passport-local').Strategy both point to the same type. What is the purpose of such a construct?
It creates a circular reference which backpoints to main object. It does not use extra memory or cause memory leak. It is the same object, just a reference to top. It's very commonly used in node.js (just log stream objects). Here apparently the library makes no use of it.
Looking at it further, it looks like this is done to have consistency across various strategies. A module could export multiple strategies. So, modules will have a separate property for each strategy. But, in this case, the module contains a single strategy. So, it seems to have been exposed both as a the module and a property in the module, such that module.Strategy will return the strategy.