If you've ever wired a currency converter into a Node.js app, you know the pattern: pick an API, write an HTTP client, handle auth, parse JSON, cache results, build a CLI on top of it. It's a tiny domain that somehow turns into a mini-project.
fx-rates is a small, focused package that collapses that work into one line — both as a library and a CLI — backed by real-time mid-market rates from the AllRatesToday API.
Why fx-rates?
- ⚡ Real-time rates, not daily snapshots — updated every 60 seconds from Reuters/Refinitiv and interbank feeds
- 🌍 160+ currencies including majors, emerging-market pairs, and precious metals (XAU, XAG)
- 📦 Zero runtime dependencies — uses native
fetch, so no bloated http client - 🖥️ Library AND CLI in one package
- 🔒 Mid-market rates — no retail markup, no hidden spread
Install
npm install fx-rates
Grab a free API key at allratestoday.com/register — no credit card required — and export it:
export ALLRATESTODAY_API_KEY="art_live_..."
Library usage
Get a rate
import { rate } from "fx-rates";
const r = await rate("USD", "INR");
console.log(r);
// {
// date: "2026-04-20",
// base: "USD",
// target: "INR",
// rate: 83.2145
// }
Convert an amount
import { convert } from "fx-rates";
const out = await convert(100, "USD", "EUR");
console.log(out);
// {
// from: { currency: "USD", amount: 100 },
// to: { currency: "EUR", amount: 92.34 },
// rate: 0.9234,
// date: "2026-04-20"
// }
Pass the API key explicitly
Prefer not to rely on environment variables? Pass it in directly:
const r = await rate("USD", "EUR", { apiKey: "art_live_..." });
CLI usage
The same package ships a CLI. After installing (globally or via npx) you can run:
npx fx-rates USD EUR
# 1 USD = 0.9234 EUR (2026-04-20)
npx fx-rates convert 100 USD EUR
# 100 USD = 92.34 EUR (rate: 0.9234, date: 2026-04-20)
Handy for scripts, shell pipelines, and one-off conversions in the terminal.
When fx-rates is the right pick
- You're building a Node.js service and don't want to take on a heavy HTTP client or a DI-heavy SDK
- You need a tiny CLI for devops / scripting — budget alerts, invoice scripts, cron jobs that normalize amounts across currencies
- You want mid-market rates (not retail FX) for accurate analytics, reporting, and financial apps
What fx-rates isn't
It's intentionally not a full SDK. There are no historical time-series endpoints, no conversion batches, no ORM-style client. If you need those, use @allratestoday/sdk — the full-featured official client. fx-rates is the "just the basics" option.
Next steps
- npm:
fx-rates - Get a free API key: allratestoday.com/register
- Docs: allratestoday.com
If you ship anything cool with it, I'd love to see it — drop a link in the comments.
Top comments (0)