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 = req.scope.resolve(
"productModuleService"
)

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

In the Examples or API Reference guides, you may see an initialization of the product module. This is only necessary if you're using the module outside the Medusa backend.


Up Next

Was this section helpful?