jeudi 5 mars 2015

Node module design pattern

I everyone ! I'm using the soap module to create an API. I want to expose specific SOAP method to developers with error and success handling based on a specific webservice.


So i'v created a module wich wrap up soap module. My question is about module.exports best practices and design.


There is many design pattern who can be apply : http://ift.tt/Lc0fEM



function MyModule(options) {
this.options = option || {};

//...
};

MyModule.prototype.anApiMethod = function(data, cb) {
//...
};

module.exports = exports = function(options) {
return new MyModule(options);
}


It is a good module design. My objective is to pass options as arguments and use the API. What's the trade-off ?


Examples:



var myModule = require('./my-module');
var webservice = myModule({'options1': 'value1'});

webservice.anApiMethod({}, function(err, res){
//do something
});

Aucun commentaire:

Enregistrer un commentaire