This is a simple currency converter API in Node.js
This application allows you to convert currencies using the latest exchange rates. It fetches the exchange rates from a third-party Monobank Public API and performs currency conversion. It also utilizes Redis to cache the currency rates for 1 hour.
Make sure you have Node.js and Redis is installed on your machine. Redis should be running on the default port 6379.
npm install
You can configure the app by copying variables from the .env.sample file to .env file.
nodemon app.js
Your app should now be running on localhost:3000.
You can also run the app using Docker. Make sure you have Docker installed on your machine.
docker-compose up
curl -X POST -H "Content-Type: application/json" -d '{
"fromCurrency": "USD",
"toCurrency": "EUR",
"amount": 100
}' http://localhost:3000/convert
{
"fromCurrency": "USD",
"toCurrency": "EUR",
"amount": 100,
"convertedAmount": 88.0
}
curl -X POST -H "Content-Type: application/json" -d '{
"fromCurrency": "USD",
"toCurrency": "ABC",
"amount": 100
}' http://localhost:3000/convert
{
"errors": [
{
"type": "field",
"value": "ABC",
"msg": "toCurrency must be a valid currency code",
"path": "toCurrency",
"location": "body"
}
]
}