openexchangerates / npm-exchange-rates

nodeJS / npm module to load real-time exchange rates from the Open Exchange Rates API
https://openexchangerates.org
89 stars 30 forks source link

Does not return any rates #12

Open madmacc opened 2 years ago

madmacc commented 2 years ago
oxr.timestamp undefined
oxr.base USD
oxr.rates {}

const oxr = require('open-exchange-rates'); oxr.set({ app_id: OXR_APP_ID })

await oxr.latest();
  // You can now use `oxr.rates`, `oxr.base` and `oxr.timestamp`
  console.log('oxr.rates', oxr.rates);
  console.log('oxr.base', oxr.base);
  console.log('oxr.timestamp', oxr.timestamp);

Using version 0.3.0 My app id works fine using: https://openexchangerates.org/api/latest.json?app_id=

UPDATE: It appears it doesn't work with "await". The following works but I am not sure how to use it like that for my use case as I need to wait for the results and then do something else.

 oxr.latest(function() {
    // You can now use `oxr.rates`, `oxr.base` and `oxr.timestamp`
    console.log('oxr', oxr);
    console.log('oxr.rates', oxr.rates);
    console.log('oxr.base', oxr.base);
    console.log('oxr.timestamp', oxr.timestamp);
  });