DEV Community

Madhushan
Madhushan

Posted on

fx-rates: Real-Time Currency Exchange Rates in Node.js (and from the Terminal)

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
Enter fullscreen mode Exit fullscreen mode

Grab a free API key at allratestoday.com/register — no credit card required — and export it:

export ALLRATESTODAY_API_KEY="art_live_..."
Enter fullscreen mode Exit fullscreen mode

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
// }
Enter fullscreen mode Exit fullscreen mode

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"
// }
Enter fullscreen mode Exit fullscreen mode

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_..." });
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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

If you ship anything cool with it, I'd love to see it — drop a link in the comments.

Top comments (0)