JavaScript Client Library for Global Exchange Rates API

Working with the Global Exchange Rates API is already straightforward using our JSON or XML endpoints.

To make integration even simpler for JavaScript developers, we’ve published an official client library on npm: globalexchangerates

This TypeScript-based exchange rates API client library works in both Node.js and browser environments, so it’s usable in backend services, web apps, and anywhere else you need currency data.

Quick Start

Install the package with your preferred package manager:

npm install globalexchangerates

Then use it like this:

import { GlobalExchangeRatesClient } from "globalexchangerates";

const client = new GlobalExchangeRatesClient("your_api_key");

const rates = await client.getLatest();

This JavaScript exchange rates API library includes helpers for all endpoints (latest, historical, etc.), with full TypeScript support.

If you’re building something in JS/TS and need currency exchange data, this should help you get started quickly.

Converting Amounts and Choosing a Provider

Convert an amount directly using the official rates, or request rates from a specific provider such as the ECB:

const conversion = await client.convert(100, "EUR", ["USD", "GBP"]);

const ecb = await client.getLatest("ECB", ["USD", "GBP"]);

The client also provides getHistorical() for date-specific rates, plus getCurrencies() and getProviders() to discover the available currencies and institutions. See the API documentation for the full method reference.

Handling Errors

Wrap calls in try/catch to handle API errors:

try {
const rates = await client.getLatest();
console.log(rates);
} catch (error) {
console.error("Error fetching exchange rates:", error);
}

Without the Library

If you prefer not to add a dependency, you can call the API directly with fetch. The key is passed as the subscription-key query parameter:

const res = await fetch(
"https://api.globalexchangerates.org/v1/latest?subscription-key=YOUR_SUBSCRIPTION_KEY&base=EUR"
);
const data = await res.json();

console.log(data.exchangeRates.USD);

Keeping the Rates Up to Date

Official rates are published once per business day, so refreshing on a schedule is usually enough to keep your data current.

The same official rates are available in other languages and tools — see our Python and C# / .NET client libraries, or the guides for Power BI and Google Sheets. The full method reference is in the API documentation. If you don’t have an API key yet, you can get one on the get-started page, with official rates from central banks and tax authorities worldwide.

Let us know if you use it or have suggestions!