i am trying to do a simple task. here is my function i am taking in a url link as parameters. i read the link, scrap it for data like title and headers. then i just try to store the data in mongo. for some reason looking at this code console prints y first and then x. why is javascript not compiling the code as it is written? any help on how i may be able to store this data in a global var. thanks i believe it is a call back error..
insertNewItem(link){
check(link, String);
var xray = new Xray();
var tname;
xray(link, 'title')(function(err, title) {
tname = title;
console.log('x', tname);
});
var header;
xray(link, 'h1')(function(err, h1) {
header = h1;
});
console.log('y',tname);
Items.insert({
url: link,
name: tname,
bio: header
});
}