enter code hereMy promise statement here is returning results as undefined. How can I access the data from promise and use it? here are my code. This will return and display the real-time schedule, but I just can't access the data and use them. Please help me with accessing the data. Thanks!
var async = require("async");
var fetch = require('node-fetch');
var Mta = require('mta-gtfs');
var mta = new Mta({
key:'my_api',
feed_id: 1
});
fetch('http://datamine.mta.info/lists-of-feeds')
//********************************************************************************************
//--------------------------------------------------------------------------------------------
//mta.stop('627').then(function (result) {
// console.log(result);
// });
//--------------------------------------------------------------------------------------------
/*
function getStopInfo(StopId){
mta.schedule(StopId).then(function (result) {
console.log('*****************************************')
for (var i=0; i<5;i++)
{
console.log('train '+[i+1]+ ' heading to North: '+result.schedule['627'].N[i]['arrivalTime']);
console.log('train '+[i+1]+ ' heading to South: '+result.schedule['627'].S[i]['arrivalTime']);
console.log('*****************************************')
}
});
}
function getInfo(StopId, callback){
if (typeof callback == 'function')
{
console.log('works')
callback(StopId);
}
else
{
console.log('err');
}
}
//console.dir(result, {depth:null, color:true});
//const info = getStopInfo(627);
//console.log(info);
var info = getInfo(627, getStopInfo);
console.log(info);
*/
async function getStopInfo(StopId){ //This is where the function is being pointed out for unexcepted token.
try{
const info = await mta.schedule(StopId);
callback(info)
} catch(error) {
console.log(error)
}
}
getStopInfo(627, info => {
console.log('yep' +info)
})