Skip to main content
Bumped by Community user
Bumped by Community user
added 92 characters in body
Source Link
NSS
  • 171
  • 5

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 () {
    procInvproc.preProcesspre(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

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 server = module.exports = {};

server.run = function () {
    procInv.preProcess(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?

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

Source Link
NSS
  • 171
  • 5

Support multi functionality in server.js

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 server = module.exports = {};

server.run = function () {
    procInv.preProcess(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?