Skip to main content
Skip to main content

Product Module

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

Features

Products Management

With the Product Module, store products and manage them through the main interface methods. Products have custom options, such as color or size, and each variant in the product sets the value for these options.

const products = await productService.create([
{
title: "Medusa Shirt",
options: [
{
title: "Color",
},
],
variants: [
{
title: "Black Shirt",
options: [
{
value: "Black",
},
],
},
],
},
])

Product Organization

The Product Module provides different data models used to organize products, including categories, collections, tags, and more.

const category = await productService.createCategory({
name: "Shirts",
})

const products = await productService.update([
{
id: product.id,
categories: [
{
id: category.id,
},
],
},
])

Configure Product Module

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

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

How to Use Product Module's Service

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

For example:

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

export async function GET(
request: MedusaRequest,
res: MedusaResponse
) {
const productModuleService: IProductModuleService =
request.scope.resolve(ModuleRegistrationName.PRODUCT)

res.json({ products: await productModuleService.list() })
}
Was this section helpful?