How to Convert USD to EUR in Node.JS

In online commerce, having a system in place to calculate exchange rates and conversions is an invaluable tool. For example, if you sell products or services through a website and have an international audience, maintaining current, accurate exchange rate data and an implementing an automatic conversion tool will make your business more approachable and improve user experience. The following API will allow you to automatically convert any source currency into any available destination currency with constantly updated exchange rate data.

Image for post
Image for post

For this API, we first need to install our client:

npm install cloudmersive-currency-api-client –save

Or, you can add this snippet to your package.json:

"dependencies": {
"cloudmersive-currency-api-client": "^1.2.0"
}

Then, we can call our function, CurrencyExchangeConvertCurrency:

var CloudmersiveCurrencyApiClient = require('cloudmersive-currency-api-client');
var defaultClient = CloudmersiveCurrencyApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveCurrencyApiClient.CurrencyExchangeApi();var source = "source_example"; // String | Source currency three-digit code (ISO 4217), e.g. USD, EUR, etc.var destination = "destination_example"; // String | Destination currency three-digit code (ISO 4217), e.g. USD, EUR, etc.var sourcePrice = 1.2; // Number | Input price, such as 19.99 in source currencyvar callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.currencyExchangeConvertCurrency(source, destination, sourcePrice, callback);

Now, you can improve your user experience and provide for easier transactions for your clients. Your personal API Key can be found on the Cloudmersive website. This will give you access to up to 800 free calls per month across our library of APIs.

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store