feedparser
is an asynchronous function. Your getfeed
function returns totalText, which is undefined at that moment. You need to pass a callback to your getfeed
function and invoke that callback with the result.
getfeed.js
module.exports = function(callback) {
then in your feedparser.on('readable') -
var totalText = ''
feedparser.on('readable',
var stream = this
, meta = this.meta
, itemData;
while (itemData = stream.read()) {
totalText += ejs.render(templateString, { item : itemData } );
}
});
feedparser.on('end', function() {
callback(totalText);
});
app.js -
getFeed(function(data) {
console.log(data); //undefined
var formattedData = "<!DOCTYPE html><html><head><title>Feed</title></head><body>" + data + "</body></html>"; //Not the prettiest thing, but it works fine
res.send(formattedData); //Just prints undefined onto the screen :(
});