To make it a bit more clear to what I'm trying to achieve.
I have a server running which includes many module, and one of the module use to check if the user role is an admin or not.
in Server.js
var loginAPI = require('myModule')(argStringType),
express = require('express');
var app = express();
Now that in the myModule.js I have few functions that already been implemented and just wanted to add one more, but this function really doesn't need to be call from the server.js instead it will be call once the person visit the URL, so I want to add something like this to the myModule.js
in myModule.js
app.get( "/post/:postid", function( req, res ) {
var id = req.param('postid');
return getContent( postid );
});
// Module.exports
module.exports = function ( arg ) {
return {
getContent: function ( id ) { },
getHeader: function ( id ) { };
};
So as you can see from the above, I have two function which is in the module.exports and they worked fine no problem except the one which is outside the module.exports that one work if I don't try to call the getContent, but that is what I'm trying to achieve. When someone visit the site by entering the URL in that format the app.get should be fire and do whatever is implemented to do.
return { exportName: exportName, [...]and after require:loginAPI.exportName(arg)app.getto always be active without being call, so once they do therequireit will be use right away.globalobject.URLthen it will be active. When they visited that site they have to access the other function to get some detail as well.exportName, why not export it?module.exports.exportName = function (arg) {...};and then call it by usingloginAPI.exportName(arg);. If that's not what you're asking, you might need to rework your question with expanded descriptions and examples.