2
\$\begingroup\$

i've node app that having the main function server.js(entry point)

Following is the server.js file code

var childModule = require("./controller/childModule");
var server = http.createServer(app);
var proxy= require('./controller/proxy');
var proc = require('./controller/runIntProcess');
var extLoader = require("./controller/extLoader");
....
var server = module.exports = {};
server.run = function () {
 proc.pre(function () {
 server.listen(app.get('port'), function (err) {
 if (err) {
 console.error(err);
 } else {
 console.log('application Listening on port: ' + app.get('port'));
 }
 proxy.web(server);
 });
 })
};
server.addNewFunctionlity= function(oDir){
 extLoader.load(oDir.folder);
};
module.exports = function () {
 server.run();
}();
server.childModule = childModule;

The code do this:

when user call to the server he need to write the following code

var myModule = require("myModule");
myModule.addNewFunctionlity({folderPath:__dirname + '/files'});
myModule.addNewFunctionlity({folderPath:__dirname + '/files2'});

The Code is working! but I've several questions :-)

  1. Does I export the childModule OK?
  2. Does the usage of my API is make sense?
  3. Does the var server = module.exports = {} is OK?

The code is running a node app which can be cousume by CMD (call to the server.js) without any args or using it by code. in addition I need to expose some API's like childModule

asked May 22, 2016 at 14:19
\$\endgroup\$
4
  • \$\begingroup\$ What is proxy, procInv and extLoader? \$\endgroup\$ Commented May 22, 2016 at 17:31
  • \$\begingroup\$ please provide some brief context about the code or have commenting properly. \$\endgroup\$ Commented May 23, 2016 at 4:44
  • \$\begingroup\$ @JosephtheDreamer - done , does it help? \$\endgroup\$ Commented May 23, 2016 at 8:12
  • \$\begingroup\$ @Neel - done , is it more clear now? \$\endgroup\$ Commented May 23, 2016 at 8:15

1 Answer 1

1
\$\begingroup\$

I wouldn't pass file folders/files to a fn like that, I'd rather pass the functionality subject like:

myModule.addNewFunctionlity('geoMapping');
myModule.addNewFunctionlity('cookieService');

then refactor you fn nomenclature, maybe

myModule.addNewFunctionlity('geo.geoMapping');
myModule.addNewFunctionlity('frontend.cookieService');

If you think you really need to setup file/folder structure, then apply maybe a setupPath() fn:

myModule.setupPath({ folderPath:__dirname + '/files2'} );

so that in 5-7 years you and others will understand at a glance what addNewFunctionlity() and setupPath() is about :)

answered May 23, 2016 at 12:32
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.