Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including money-converter with all npm packages installed. Try it out:

var moneyConverter = require("money-converter")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

money-converter v1.0.3

A npm module that looks at mutliple exchanges when determining the fx rate

Money Converter

There are plenty of currency converter packages out there, each getting their conversion rates from different places. Money Converter looks at multiple sources to ensure that you always have the most accurate exchange rate avaialable. Its fast, simple, light weight and most importantly, fault resistant.

Install

npm install money-converter

Usage

To make sure that money-converter is as fast as possible, you pass it in an array of currencies and a bse currency. money-converter will then load the conversion rate between your base currency and each of the other currencies. This async process must be completed before the module can be used

we're going to be using the popular async module here for demonstation of how load the currencies before using them

make sure to include the base currency in the list of currencies you pass into the constructor

var MoneyConverter = require('monver-converter');
var async = require('async');

var money;

async.series([

  // load and cache currency conversions
  // the base currency is USD
  function(done) {
    money = new MoneyConverter('USD', ['CAD', 'GBP', 'EUR', 'USD'], done)
  }

  // example of how we want to actually use it
  function(done) {

    money.convert(1000, {from: 'USD', to: 'EUR'});
    // => 914

    money.convert(10, {from: 'CAD', to: 'EUR'});
    // => 6.655501347120076

    money.convert(1, {from: 'GBP', to: 'USD'});
    // => 1.50534397109739

    done();
  }
]);

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free