I'm trying to return an object in a node js app but it's returning as undefined,I think it's an issue with async but not sure how to go about it. Thanks in advance!
var express = require('express');
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
var app = express();
var u = require("underscore");
console.log("Starting Application");
function getTeams() {
request.get('http://removed.dev/', null, function (error, response, html) {
if (!error && response.statusCode == 200) {
$ = cheerio.load(html);
var links = $('#f10 a, #f186 a');
if (links.length > 0) {
var output = {};
$(links).each(function (i, v) {
var link = $(this).attr("href");
var title = $(this).text();
var team = {
'name': title,
'link': link
};
output[i] = team;
});
}
}
});
return output;
};
var teams = getTeams(); // undefined
app.get('/', function (req, res) {
});
app.listen(3000);