What does CommonJs module pattern do?

 Posted by Rajnilari2015 on 3/7/2016 | Category: Node.js Interview questions | Views: 2177 | Points: 40

CommonJs module pattern helps to add references to various js libraries as opposed to adding script tags in individual html pages thereby prevents all the UI pages from being getting polluted.The CommonJs module pattern only allowed one module per file - it there by eliminates circular dependencies and helps in finding out the properties regarding the current module.


// ourpackage is a dependency needed in the project

var lib = require('ourpackage');

// perform some action
function Print(){
lib.log('it is only a test');

// export Print to other modules
exports.Print = Print;

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response