0

I have a problem in my Node.js project. I trying to return an object "jsonData" by calling a function from another function that located in different js file.

functions.js:

var request = require('request');
var cheerio = require('cheerio');
var jsonData = {};

global.returnFunc = function returnFunc(url)
{
  if (url === '****')
  {
    return lacurrency();
  }
}

var lacurrency = function()
{
  request(****, function (error, response, html)
  {
    if (!error && response.statusCode == 200) {
      var $ = cheerio.load(html);


      var i = 0;
      $('a.table-row').each(function(i, element){
          var a = $(this).children('span');
          jsonData[i++] = 
          {
            curreny: a.eq(0).text(),
            buy: a.eq(4).text(),
            sell: a.eq(3).text()
          };

      })

    }
    return jsonData;
  });
}

DOTO_list.js:

require("./functions.js");
console.log(global.returnFunc(****));

When I run DOTO_list.js, I always got "undefined" but if I check typeof "global.returnFunc" => function.

How I can get the "jsonData" object back to TODO_list.js?

DD apps
  • 57
  • 1
  • 6

0 Answers0