Wednesday, 17 May 2017

How to read JSON file from URL and assign it into a global variable in NodeJS?

var url = 'https://myurl.com/file.json';
request(url, function (error, response, body) {
  if (!error && response.statusCode == 200) {
     var jsonObject = JSON.parse(body);
     console.log(jsonObject);
  }
});

I've found the way to get JSON file from URL but it's a little bit struggle for me to assign it to a global variable. In this case, how can I deal with the jsonObject?



via D. Matthew

No comments:

Post a Comment