Installation
Package Manager
Install @toneflix/money using your preferred package manager:
npm install @toneflix/moneypnpm add @toneflix/moneyyarn add @toneflix/moneyRequirements
- Node.js: 16.x or higher
- TypeScript: 4.5 or higher (optional, for TypeScript projects)
Importing
After installation, you can import the library in your project:
ES Modules
import {
Money,
Exchange,
ExchangeRateApi,
FrankfurterApi,
} from '@toneflix/money';CommonJS
const {
Money,
Exchange,
ExchangeRateApi,
FrankfurterApi,
} = require('@toneflix/money');TypeScript Configuration
The library includes TypeScript type definitions out of the box. No additional setup is required for TypeScript projects.
{
"compilerOptions": {
"moduleResolution": "node",
"esModuleInterop": true
}
}Exchange Rate Providers
Currency conversion is handled through exchange-rate providers.
ExchangeRateApi is the default provider and preserves the existing API-key based workflow.
import { Exchange, ExchangeRateApi } from '@toneflix/money';
Exchange.setProvider(ExchangeRateApi);You can also use FrankfurterApi, which does not require an API key:
import { Exchange, FrankfurterApi } from '@toneflix/money';
Exchange.setProvider(FrankfurterApi);Provider selection does not change how you use the Exchange API:
const result = await Exchange.from('USD').to('EUR').convert(100);ExchangeRateApi Setup
If you're using the default ExchangeRateApi provider, you'll need an API key from ExchangeRate-API.
You can configure the API key using an environment variable:
EXCHANGERATE_API_KEY=your-api-key-hereThe library will automatically load your environment configuration if available.
Alternatively, you can set the API key programmatically:
import { Exchange } from '@toneflix/money';
Exchange.setApiKey('your-api-key-here');You can also explicitly select the provider:
import { Exchange, ExchangeRateApi } from '@toneflix/money';
Exchange.setProvider(ExchangeRateApi);
Exchange.setApiKey('your-api-key-here');Exchange.setApiKey() remains supported for backwards compatibility.
FrankfurterApi Setup
FrankfurterApi does not require an API key.
Simply select it as your exchange-rate provider:
import { Exchange, FrankfurterApi } from '@toneflix/money';
Exchange.setProvider(FrankfurterApi);
const result = await Exchange.from('USD').to('EUR').convert(100);No environment variable or Exchange.setApiKey() call is required when using Frankfurter.
Next Steps
Now that you've installed the library:
- Check out the Quick Start
- Learn about Currency Conversion
- Explore the API Reference
