i’m trying to create a small app to exchange books
I previously used a request directly on google books baut i would like to use an NPM module called “node-isbn” as it’s connected to 3 databases.
In my code, i grab the ISBN from an input and i want to use it in my request.
I checked my code but i don’t understand why i get an undefined error.
I create my call like this :
Meteor.call(‘getISBN’, input , function(error, response) {
if(error){
console.log(‘ERROR :’, error);
}else{
console.log(‘response :’, response);
Session.set(“isbns”, response.items);
var getData = Session.get(“isbns”);
var getTitle = getData[0].volumeInfo.title;
var getDescription = getData[0].volumeInfo.description;
var getAuthors = getData[0].volumeInfo.authors;
var getIdentifier = getData[0].volumeInfo.industryIdentifiers[1].identifier;
var getImage = getData[0].volumeInfo.imageLinks.thumbnail;
console.log(getImage);
books.insert({title: getTitle, authors: getAuthors, isbn13: getIdentifier, description: getDescription, image: getImage},function (error,result){
if (error) console.log(error);
if (result) console.log(result);
})
}
})
}
});
and, my server.js is like that :
Meteor.startup(function () {
// code to run on server at startup
var isbn = Npm.require('node-isbn');
Meteor.methods({
'getISBN': function(input){ // récupération du paramètre passé par le meteor.call
//console.log(bookList);
isbn.resolve(input), function(error, book) {
if (error){
console.log('Book not found',error);
}else{
return '%j';
}
}
}
})
})
on my browser, in my console, i get this message :
response : undefined
meteor.js?hash=ec96c6f…:913 Exception in delivering result of invoking ‘getISBN’: TypeError: Cannot read property ‘items’ of undefined
As i want to learn from my mistakes, can you tell me what’s wrong ?
Thanks