Skip to main content
Skip to main content

Currency Module

The Currency Module is the @medusajs/currency NPM package that provides currency-related features in your Medusa and Node.js applications.


Features

Currency Retrieval

List and retrieve currencies stored in your application.

By default, the module, on application start, adds currencies defined in this file to the database.

const currency = await currencyModuleService.retrieve("usd")

Support Currencies in Modules

Other commerce modules use currency codes in their models or operations. You can use the Currency Module to retrieve a currency code and its details.

An example with the Region Module:

const region = await regionModuleService.retrieve("reg_123")
const currency = await currencyModuleService.retrieve(
region.currency_code
)

Configure Currency Module

After installing the @medusajs/currency package in your Medusa application, add it to the modules object in medusa-config.js:

medusa-config.js
const modules = {
// ...
currency: {
resolve: "@medusajs/currency",
},
}

How to Use Currency Module's Service

You can use the Currency Module's main service by resolving from the dependency container the resource ModuleRegistrationName.CURRENCY imported from @medusajs/modules-sdk.

For example:

import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"

export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService =
req.scope.resolve(ModuleRegistrationName.CURRENCY)

res.json({
currencies: await currencyModuleService.list(),
})
}
Was this section helpful?