Node.js Currency Exchange Rate API Documentation
How to use our Node.js Currency Exchange Rate API with Axios for real-time currency conversion.
Introduction to the Node.js Currency Exchange Rate API
Welcome to the Node.js Currency Exchange Rate API documentation. Our API provides an easy and reliable way to integrate real-time currency exchange rates into your Node.js applications. Suitable for both personal and professional use, our API offers a straightforward integration process with minimal setup.
Key Features
- Seamless Integration: Integrate our API into your Node.js projects effortlessly using simple GET requests.
- Fast and Accurate JSON Responses: Receive quick and human-readable JSON responses, easily parsed with Node.js.
For more detailed information on request types and error responses, please check our Main Documentation.
Getting Started with Node.js: Currency Conversion Example
To use our API with Node.js, you need to obtain a free API key. Register here to get your API key.
Below is an example of how to fetch and utilize currency conversion rates using axios
:
-
Install the
axios
package:npm install axios
-
Example Code:
const axios = require("axios");
// Define your API key and base URL
const apiKey = "YOUR-API-KEY";
const baseCurrency = "USD";
const url = `https://api.currencyexchangerate-api.com/v1/${apiKey}/latest/${baseCurrency}`;
// Function to fetch exchange rates
async function fetchExchangeRates() {
try {
const response = await axios.get(url);
const data = response.data;
// Check if the request was successful
if (data.result === "success") {
// Access conversion rates
const conversionRate = data.conversion_rates["EUR"];
console.log(
`Exchange rate from ${baseCurrency} to EUR: ${conversionRate}`,
);
} else {
console.error("Failed to fetch exchange rates:", data);
}
} catch (error) {
console.error("Error fetching data:", error);
}
}
// Execute the function
fetchExchangeRates();
Sample JSON Response
Here’s a sample JSON response from the API with USD as the base currency code:
{
"result": "success",
"base_code": "USD",
"qouta": 100,
"remining": 78,
"conversion_rates": {
"USD": 1,
"AED": 3.6725,
"AFN": 71.3023,
...
}
}
For additional details on request types, error handling, and more, please visit our Main Documentation.
Need Help?
If you have any questions or need further assistance, don’t hesitate to contact us. We’re here to assist you!