currency_converter_lite
v1.0.6
Published
an currency converter lite npm package
Maintainers
Keywords
Readme
💱 Currency Converter (TypeScript)
A simple Node.js & TypeScript-based CLI or backend utility that fetches real-time currency exchange rates using the FreeCurrencyAPI.
🚀 Features
- 🌐 Fetches latest exchange rates in real time
- 💵 Supports multiple base and target currencies
- ⚡ Uses async/await for clean async code
- 🧱 Written in TypeScript (type-safe and modular)
- 🔒 API key loaded from environment variables
📦 Installation
1️⃣ Install the package and dependencies
npm install currency_converter_lite dotenv
2️⃣ Create a .env file
Inside your project root folder, create a file named .env and add your FreeCurrencyAPI key:
KEY=Your currency converter API key
💡 You can get a free API key from https://freecurrencyapi.com
3️⃣ Create a index.js (or .ts) file
import { convertCurrency } from 'currency_converter_lite';
const convert = async () => {
const result = await convertCurrency('USD', 'EUR', 100);
console.log(`Converted amount: ${result}`);
}
convert();
🧠 OR
import { convertCurrency } from 'currency_converter_lite';
console.log(await convertCurrency('USD', 'EUR', 100));
📤 Example Input
💱 Exchange Rate (fromCurrency, toCurrency, amount)
📤 Example Output
💱 Exchange Rate (USD → EUR): 0.9456
🧠 Example Code
import 'dotenv/config';
import Freecurrencyapi from '@everapi/freecurrencyapi-js';
const freecurrencyapi = new Freecurrencyapi(process.env.KEY as string);
async function getLatestRate() {
try {
const response = await freecurrencyapi.latest({
base_currency: 'USD',
currencies: 'EUR'
});
console.log('💱 Exchange Rate (USD → EUR):', response.data.EUR);
} catch (error) {
console.error('❌ Error fetching currency data:', error);
}
}
getLatestRate();
✨ Author
Md. Mohiuddin Murad
📧 [email protected]
