Fetch live and historical exchange rates in JavaScript and Node.js. Install our SDK with npm or call the REST API with fetch.
Install the official JavaScript SDK and fetch your first exchange rate in under a minute.
npm install @exchangerateapi/sdk
import ExchangeRateAPI from '@exchangerateapi/sdk';
const client = new ExchangeRateAPI({ apiKey: 'era_live_YOUR_API_KEY' });
// Get the latest USD to EUR rate
const { rates } = await client.latest({ base: 'USD', symbols: ['EUR'] });
console.log(`1 USD = ${rates.EUR} EUR`);
// Output: 1 USD = 0.9215 EUR
era_live_. The free plan includes 300 requests per month.
The @exchangerateapi/sdk npm package wraps every API endpoint and handles authentication, retries, and TypeScript types for you.
import ExchangeRateAPI from '@exchangerateapi/sdk';
const client = new ExchangeRateAPI({ apiKey: 'era_live_YOUR_API_KEY' });
// Multiple currencies in one call
const { rates } = await client.latest({ base: 'USD', symbols: ['EUR', 'GBP', 'JPY'] });
console.log(rates); // { EUR: 0.9215, GBP: 0.7891, JPY: 151.42 }
// Convert 1000 USD to EUR
const result = await client.convert('USD', 'EUR', 1000);
console.log(`$1,000 = ${result.result} EUR`);
// Historical conversion at a specific date
const past = await client.convert('USD', 'EUR', 1000, { date: '2026-01-15' });
// Rates for a specific date
const data = await client.forDate('2026-01-15', { base: 'EUR', symbols: ['USD', 'GBP'] });
// Historical rates by period
const history = await client.getHistoricalRates('USD', 'EUR', '30d');
const { symbols } = await client.symbols();
console.log(symbols); // { USD: 'United States Dollar', EUR: 'Euro', ... }
If you prefer to call the API directly without the SDK, use the native fetch API available in Node.js 18+ and all modern browsers.
const response = await fetch(
'https://exchange-rateapi.com/api/v1/rates?source=USD&target=EUR',
{ headers: { 'Authorization': 'Bearer era_live_YOUR_API_KEY' } }
);
const data = await response.json();
console.log(`1 USD = ${data[0].rate} EUR`);
// Output: 1 USD = 0.9215 EUR
const response = await fetch(
'https://exchange-rateapi.com/api/v1/rates?source=USD&target=EUR,GBP,JPY',
{ headers: { 'Authorization': 'Bearer era_live_YOUR_API_KEY' } }
);
const rates = await response.json();
rates.forEach(r => console.log(`1 USD = ${r.rate} ${r.target}`));
// Output:
// 1 USD = 0.9215 EUR
// 1 USD = 0.7891 GBP
// 1 USD = 151.42 JPY
async function getRate(source, target) {
try {
const response = await fetch(
`https://exchange-rateapi.com/api/v1/rates?source=${source}&target=${target}`,
{ headers: { 'Authorization': 'Bearer era_live_YOUR_API_KEY' } }
);
if (!response.ok) {
if (response.status === 401) throw new Error('Invalid API key');
if (response.status === 429) throw new Error('Rate limit exceeded');
throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();
return data[0].rate;
} catch (error) {
console.error('Failed to fetch rate:', error.message);
throw error;
}
}
[
{
"rate": 0.9215,
"source": "USD",
"target": "EUR",
"time": "2026-05-15T12:00:00Z"
}
]
[
{ "rate": 0.9215, "source": "USD", "target": "EUR", "time": "2026-05-15T12:00:00Z" },
{ "rate": 0.7891, "source": "USD", "target": "GBP", "time": "2026-05-15T12:00:00Z" },
{ "rate": 151.42, "source": "USD", "target": "JPY", "time": "2026-05-15T12:00:00Z" }
]
@exchangerateapi/sdk package includes full TypeScript type definitions out of the box. No need to install separate @types packages.
Get your free API key and start fetching exchange rates in JavaScript in under a minute.
Get Free API Key →