Im writing a nodejs module and I need to pass variable data from the main file to the functions, im doing this:
var region;
var api_key;
exports.region = region;
exports.api_key = api_key;
module.exports = {
getSummonerId: function(sum, callback) {
var summoners = {};
var summoner = sum.replace(/\s+/g, '');
request("http://ift.tt/1zY3bLg"+region+"/v1.4/summoner/by-name/"+summoner+"?api_key="+api_key, function(error, response, body) {
summoners[summoner] = JSON.parse(body);
callback(summoners[summoner][summoner].id);
});
}
}
And in the main file:
var lol = require('./apiwrapper.js');
lol.api_key = "example";
lol.region = "las";
lol.getChampions(function(data) {
console.log(data);
})
But from apiwrapper.js those two variables value is always "undefined".
Can some point me in the right direction?
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire