Home
Blog
Product

Announcing Product Module

Jun 20, 2023 by

Riqwan avatar

Riqwan Thamir

Riqwan avatar
Carlos avatar

Carlos Rodrigues

Carlos avatar
Adrien avatar

Adrien de Peretti

Adrien avatar
Frane avatar

Frane Polić

Frane avatar

4 authors

Today, we are thrilled to bring our commerce building blocks closer to frontend frameworks and serverless environments with the beta release of our Product Module.

Announcing Product Module - Featured image

Building rich commerce experiences often starts in the front end. But the backend is what defines the boundaries of what’s possible. This realization is what motivated Medusa and our approach to simplifying commerce development.

While Medusa has made building deep customization in your backend easy, creating these customizations requires developers to switch contexts between storefront and backend codebases.

Today, we are thrilled to bring our commerce building blocks closer to frontend frameworks and serverless environments with the beta release of our Product Module.

The Product Module enables developers to access Products, Variants, Categories, and more through a standalone package that can be installed and run in Next.js functions and other Node.js compatible runtimes.

Usage Example with Next.js

Here is what the Product Module looks like used in a Next.js function:

// app/api/products/route.ts
import { NextResponse } from 'next/server'
import { initialize } from "@medusajs/product"
export async function GET(request: Request) {
const productService = await initialize()
const products = await productService.list({
tags: { value: ["featured"] },
}, {
take: 5
})
return NextResponse.json({ products })
}

With the Copy to clipboardinitialize call, the Product Module establishes a connection to your database and gives you a Product Service to run queries through.

When installed, the Product Module feels like an extension of your codebase that you can use to build bespoke experiences across your storefront with minimal friction and full control.

Learn more about how to use the Product module in our documentation.

Serverless Compatibility

The Product Module works independently of your Medusa backend and can be deployed directly to serverless environments like Vercel. This new deployment mode has many benefits, like providing auto-scaling during traffic spikes without configuring advanced infrastructure.

Product Module Demo

To demonstrate how the Product Module works with Vercel and Next.js, we have built an ecommerce personalization demo. The demo uses the visitor’s location and a user’s session to personalize what products are shown to the customer first.

The personalization code runs directly in a Next.js function deployed to Vercel and uses Medusa’s Product Module to query and respond with relevant products.

You can check out the demo here and learn more about how it works.

Runs in any Node.js project

The Product Module can be used in any Node.js project, including other frontend frameworks like Nuxt, SvelteKit, and Remix, but also in more traditional Node applications.

This makes Medusa portable to existing projects that need to orchestrate and manage products. As more of Medusa’s features adopt this new approach, this opens an incremental migration path for larger applications.

What’s next?

With the initial release of the Product Module, the scope has been constrained to read-only operations, but this is still powerful enough for you to play around with and understand our direction.

In the coming weeks, we will be working on adding write operations to the Product Module, making it possible to create and update Products, Variants, and more through the module.

Later this year, we will ship more modules that adopt this new approach and pushes boundaries for what’s possible in digital commerce.

If you have feedback or ideas for improvements, please join the conversation in our Discord or GitHub Discussions.

Check out more product announcements on our Recap page. You can also learn more about the Product module in our documentation.

Share this post

Try Medusa

Spin up your environment in a few minutes.