This package provides a simple interface to fetch real-time currency exchange rates from Google search results.
You can install the package using npm:
npm install currency-converter-rate
const { CCR } = require('currency-converter-rate');
async function getExchangeRate(fromCurrency, toCurrency, decimalPlaces) {
try {
const rate = await CCR({ fromCurrency, toCurrency, decimalPlaces });
console.log(`1 ${from} is equal to ${rate} ${to}`);
} catch (error) {
console.error('Failed to get exchange rate:', error);
}
}
getExchangeRate('USD', 'EUR', 2);
-
from
: The currency code to convert from (e.g., 'USD'). -
to
: The currency code to convert to (e.g., 'EUR'). -
afterDecimal
: (Optional) The number of decimal places to round the exchange rate to. Default is 2.
Returns: A Promise
that resolves to the exchange rate as a number
.
- currency
- exchange
- rate
- converter
- currency-converter
- currency-exchange
- real-time
- google-search
This project is licensed under the MIT License - see the LICENSE.md file for details.