Even if I program with object-oriented languages (C++, C#, AS3) I have still some problems with the basic usage of JS for its form.
What I need is to make accessible one function inside a module.export in nodeJS.
I have this auth.js file with a function inside:
module.exports = function(app,passport,pg,user,razza){
var Pg = pg;
var User = user;
var Razze = razza;
updatePgXP: function (){
console.log("!!!!!!!!!!!!!Add XP!!!!!!!!!!!!!");
}
//....and the story goes on...
}
And I would like to call updatePgXP() in my server.js (something) like this:
var authRoute = require('./app/routes/auth.js')(app,passport,models.pg,models.user,models.razze);
//doing stuff, and at some point...
io.sockets.on('connection', function(socket){
socket.on('send message', function(data){
authRoute.updatePgXP();
}
}
All is working perfectly, I just can't figure out how can I access the function inside the auth.js from outside. It needs to stay inside the export module because it will need the vars declared on top after the module.export to operate.
At this moment fires an undefined error on the function updatePgXP() when I call it.
Many thanks to anyone can help.