Skip to main content
Skip to main content

Install Product Module in Medusa

In this document, you'll learn how to install the Product module using NPM in the Medusa backend.

Step 1: Install Module

To install the Product module, run the following command in the root directory of the Medusa backend:

npm install @medusajs/product

Step 2: Add Module to Configurations

In medusa-config.js, add the product module to the exported object under the modules property:

medusa-config.js
module.exports = {
// ...
modules: {
// ...
productService: {
resolve: "@medusajs/product",
},
},
}

Step 3: Run Migrations

Run the following command to reflect schema changes into your database:

npx medusa migrations run

Use the Module

You can now start using the module's ProductModuleService by resolving it through dependency injection.

For example:

import type { 
MedusaRequest,
MedusaResponse
} from "@medusajs/medusa";
import {
ProductModuleService
} from "@medusajs/product"

export async function GET(
req: MedusaRequest,
res: MedusaResponse
) {
const productModuleService: ProductModuleService =
req.scope.resolve(
"productModuleService"
)

return res.json({
products: productModuleService.list()
})
}

Start Development

You can refer to the Example Usages documentation page for examples of using the Product module.

You can also refer to the Module Interface Reference for a detailed reference on all available methods.

Was this section helpful?