I am making my nodejs code modular and I am bit confused. I have a working example just wanted to know if it is efficient to do it this way. what i need to do is pass paramater to the module when loading it so that those modules can use some other modules. I have use module.exports to provide a function which returns object. Is this correct way to write modules?
var params = {//obj with other modules return};
var api_helper = require('./library/api_helper')(params);
my api_helper module
module.exports = function (params){
var app = params.app
, express = params.express
, dbConnection = params.dbConnection
, crypto = params.crypto
, return_obj = {};
//validate request
return_obj.validate_request = function(req, res, next){
//req validation here
};
//check req
return_obj.checkReq = function (req, res, next){
//req check here
}
return return_obj;
}