node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป



We use purrency in node.js as a quick and dirty solution to fetch exchange reference rates from the official and sometimes shaky ECB API

It is designed to go hand in hand with money.js to allow simple conversions out of the box.

purrency leverages the event class to allow adding your own listeners for fetch & error events as illustrated in the example below.

purrency's XML references are hardcoded in the script and far from good-looking, but it appears that the module seems to do it's job pretty well, considering that the API more than sometimes is unreachable. So if the code make your eyes bleed, rock on and make a pull request.


npm install purrency

Example usage

var purrency = require('purrency');

// Change default base currency from EUR (default) to USD
purrency.settings.default_currency = 'USD';'fetch', function(rates){
    // Convert exchange rates with money.js
    // See for docs
    var fx = require('money');
    fx.rates = rates.rates;
    fx.base = purrency.settings.default_currency;
    fx.settings = {from : purrency.settings.default_currency /*, to : "SEK"*/}; // Defaults
    // Store a daily record of currencies in database:
    var mongo = require('mongoskin'),
        db = require('mongoskin').db('localhost');
    mongo.db.collection('currencies').findAndModify({timestamp: rates.timestamp}, [], rates, {upsert: true}, function(err, d) {
        console.log("Stored currencies in database!");
});'error', function(err){

// Fetch currencies


See LICENSE file.

Copyright (c) 2012 Joakim Brantingson