My Sites


Sunday, April 10, 2016

What is CommonJS pattern ?

CommonJS pattern in commonly used in many javascript frameworks, libraries and environments. The best example is Node.js. The objective of this pattern is to encapsulate your javascript files into reusable modules so that it can be referenced by other modules.
  • Get reference to dependency
var dependency = require('/path/to/file');
  • Declare Module
var MyModule ={}
  • Expose to others
module.exports = MyModule;

No comments:

Post a Comment