Welcome to the UnirateAPI Node.js documentation! Our free exchange rate API provides real-time currency conversion capabilities that you can easily integrate into your Node.js applications. Whether you're building a web server, financial dashboard, or any other system that needs currency conversion, our API has you covered.
UnirateAPI is designed to be developer-friendly and reliable, with a focus on simplicity and performance. We provide both direct API access using standard HTTP clients and an official Node.js client library built with TypeScript for type-safe integration.
For more detailed information about our API endpoints, rate limits, and advanced features, please check our main API documentation.
Below you'll find examples showing how to use our API with Node.js, both directly and using our official client library.
You can use our API in Node.js either by making direct HTTP requests or by using our official client library. We'll show you both approaches below.
// Option 1: Using Node.js fetch API directly (Node.js 18+ or with node-fetch)
// Direct API request example
async function convertCurrency(apiKey, fromCurrency, toCurrency, amount) {
const baseUrl = 'https://api.unirateapi.com/api';
const url = `${baseUrl}/convert?api_key=${apiKey}&from=${fromCurrency}&to=${toCurrency}&amount=${amount}`;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching data:', error);
throw error;
}
}
// Example usage
async function main() {
try {
const apiKey = 'YOUR_API_KEY';
const result = await convertCurrency(apiKey, 'USD', 'EUR', 100);
console.log(`Converted amount: ${result.result} ${result.to}`);
} catch (error) {
console.error('Error:', error.message);
}
}
main();
// Option 2: Using the official UnirateAPI Node.js client library
// First, install the library: npm install unirate-api
// ES Modules
import { UnirateClient } from 'unirate-api';
// OR CommonJS
// const { UnirateClient } = require('unirate-api');
// Initialize the client with your API key
const client = new UnirateClient('YOUR_API_KEY');
// Get exchange rate between currencies
async function getExchangeRateExample() {
const rate = await client.getRate('USD', 'EUR');
console.log(`1 USD = ${rate} EUR`);
// Convert amount between currencies
const amount = await client.convert(100, 'USD', 'EUR');
console.log(`100 USD = ${amount} EUR`);
// Get list of supported currencies
const currencies = await client.getSupportedCurrencies();
console.log('Supported currencies:', currencies.slice(0, 5), '...');
}
getExchangeRateExample().catch(error => {
console.error('API Error:', error.message);
});
// Direct API Response:
{
"from": "USD",
"to": "EUR",
"amount": 100,
"result": 92.45
}
// Client Library Output:
1 USD = 0.9245 EUR
100 USD = 92.45 EUR
Supported currencies: [ 'USD', 'EUR', 'GBP', 'JPY', 'AUD' ] ...
Sign up now to get your API key and start converting currencies in your JavaScript applications.
Get Your API Key