Saturday, 15 April 2017

string from lodash .template wont return in node js

For some reason I cant return the string from a lodash template. I can print the string in the function but once the function ends nothing else happens, i.e. console.log doesnt work for the string that was returned or anything for that matter

this is where the function is called

var prompt = stopInfo.getStopStatus(stopNumber);

and this is the function

function stopInfo() {
}

stopInfo.prototype.getStopStatus = function(stopNumber) {
var options = {
  method: 'GET',
  uri: ENDPOINT + '?stopid=' + stopNumber + '&maxresults=1&format=json',
  json: true
};

requestPromise(options).then(function(stopStatusObject) {
  if (true) { // check if error from dublin bus
    console.log(stopStatusObject);
    //var template = _.template('The ${busNumber} bus will arrive in ${dueTime}');
    var template = _.template(' <%= error %>');
    var test = template({
        'error': 'test'
  //    busNumber: stopStatusObject.results.route,
  //    dueTime: stopStatusObject.results.duetime
    });
    console.log(test);
    return test;
  }
}).catch(function(err) {
  console.log("error gettin stop info: " + err);
  var prompt = "I didn\'t have data for stop number " + stopNumber;
  return prompt;
});
};



via user3408117

No comments:

Post a Comment