node.js - Breaking up node module code (for a library/api client) -


i'm writing node module consume rest api service. intents , purposes might it's twitter (though it's not).

the api not small. on dozen endpoints. given want offer convenience methods each of endpoints need split code on multiple files. 1 file far large.

right testing pattern outline below, appreciate advice other means might break code. goal extend prototype of single object, using multiple files.

here's "model" i'm using far, don't think idea:

twitterclient.js

function twitterclient(){   this.foo = "bar"; }  require("fs").readdirsync("./endpoints").foreach(function(file) {   require("./endpoints/" + file)(twitterclient); });  var exports = module.exports = twitterclient; 

endpoints/endpointa.js etc

module.exports = function(twitterclient){   twitterclient.prototype.somemethod = function(){     //do things here   } } 

the basic idea file in endpoints folder automatically loaded , twitterclient passed in it, it's prototype can accessed/extended.

i don't plan stick pattern because reason seems bad idea me.

any suggestions of better patterns appreciated, cheers


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -