0

I am trying to do a http request to fixer.io to request some exchange rate data. This is the code I am using:

var url = "http://data.fixer.io/api/latest?access_key=" + API + "&base=" + Currency + "&symbols=" + RequestCurrencies;

var request = require('request');

request(url, function (error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log("Data",body);
        console.log("Body",body.base);

The result in body looks good:

  {"success":true,"timestamp":1521058763,"base":"EUR","date":"2018-03-14","rates":{"USD":1.237167}}

But in body.base I just get "Body undefined".

What am I doing wrong?

Alexander Ko
  • 195
  • 18

1 Answers1

1

The problem was that I haven't parsed the JSON file. After adding this line it worked:

 var response = JSON.parse(body1);
Alexander Ko
  • 195
  • 18