npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nand_currency_converter

v1.0.1

Published

A simple currency converter library for Node.js using ExchangeRate-API

Readme

Currency Converter

A lightweight and easy-to-use Node.js package for converting currency amounts using the ExchangeRate-API. This package provides a simple asynchronous interface to fetch real-time exchange rates and convert values between different currencies with minimal setup.


Features

  • Real-time Currency Conversion — Fetches current exchange rates for accurate conversion.
  • Simple API — Easy-to-use asynchronous function returning promises.
  • Robust Error Handling — Gracefully handles API errors and invalid inputs.
  • Lightweight — Minimal dependencies, optimized for fast performance.
  • Extensible — Easily integrate into existing Node.js applications or CLI tools.

Table of Contents


Installation

You can install the package via npm:

npm i nand_currency_converter

Prerequisites

  • Node.js v12 or higher.
  • An API key from ExchangeRate-API. Sign up for a free or paid plan depending on your requirements.

Usage

Import the package and call the convertCurrency function with the desired amount, source currency code, and target currency code.

const { convertCurrency } = require('currency-converter-your-package-name');

async function runConversion() {
  try {
    const convertedAmount = await convertCurrency(100, 'USD', 'INR');
    console.log(`Converted amount: ${convertedAmount}`);
  } catch (error) {
    console.error('Conversion error:', error.message);
  }
}

runConversion();

Sample Output

API response: {
  "result": "success",
  "documentation": "https://www.exchangerate-api.com/docs",
  "terms_of_use": "https://www.exchangerate-api.com/terms",
  "time_last_update_unix": 1748822401,
  "time_last_update_utc": "Mon, 02 Jun 2025 00:00:01 +0000",
  "time_next_update_unix": 1748908801,
  "time_next_update_utc": "Tue, 03 Jun 2025 00:00:01 +0000",
  "base_code": "USD",
  "target_code": "INR",
  "conversion_rate": 85.6031,
  "conversion_result": 8560.31
}
Converted amount: 8560.31

API Reference

convertCurrency(amount, fromCurrency, toCurrency)

| Parameter | Type | Description | | -------------- | ------ | ------------------------------------------------------- | | amount | number | The numeric value to convert (e.g., 100). | | fromCurrency | string | ISO 4217 currency code to convert from (e.g., "USD"). | | toCurrency | string | ISO 4217 currency code to convert to (e.g., "INR"). |

Returns a Promise<number> that resolves with the converted currency amount.

Throws an error if:

  • The API returns an error (e.g., invalid currency code).
  • The network request fails.
  • Input parameters are invalid.

Error Handling

The function throws descriptive errors which can be caught and handled in your application:

  • Currency conversion failed: <error message> for network or API errors.
  • Specific error types from the API, such as "unsupported-code" if an unsupported currency code is provided.

Example:

convertCurrency(100, 'XYZ', 'INR')
  .catch(err => {
    console.error(err.message); // "Currency conversion failed: unsupported-code"
  });

Development & Configuration

API Key Setup

Replace the placeholder API key in index.js with your own key from ExchangeRate-API:

const apiKey = "YOUR_API_KEY_HERE";

Environment Variables (Recommended)

For better security, you can use environment variables instead of hardcoding your API key:

const apiKey = process.env.EXCHANGE_RATE_API_KEY;

And run your application with:

EXCHANGE_RATE_API_KEY=your_api_key node test.js

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

Please follow these guidelines:

  • Fork the repository and create your branch from main.
  • Write clear commit messages.
  • Include tests for new features or bug fixes.
  • Run linting and tests before submitting a pull request.

License

This project is licensed under the MIT License.


Support

If you encounter any issues or have questions, please open an issue on the repository or contact the maintainer.


References

Created and maintained by [Nand Kumar Sahu].