Reputation: 945
Im writing an api for project and got a rare error with this function
exports.getSummonerId = function(sum, callback) {
var summoners = {};
var summoner = sum.replace(/\s+/g, '');
request("https://na.api.pvp.net/api/lol/"+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);
});
}
The call is:
var lol = require('./apiwrapper.js');
lol.getSummonerId(function(data) {
console.log(data);
});
I get:
lol-test/apiwrapper.js:11
var summoner = sum.replace(/\s+/g, '');
^
TypeError: Object function (data) {
console.log(data);
} has no method 'replace'
If I run the code without the exports, directly from apiwrapper.js everything runs normal.
Any ideas?
Thanks in advance.
Upvotes: 0
Views: 70
Reputation: 6476
Your function has 2 parameters, summoner name and callback function. Try this:
lol.getSummonerId("player", function(data) {
console.log(data);
});
Upvotes: 2