Skip to content

medusajs/product-module-demo

Repository files navigation

Medusa logo

Medusa Product Module demo

Follow @medusajs

Medusa Product Module demo in Next.js functions

This demo showcases our Product Module running in a serverless Next.js function. In the demo, we're using the Product Module to personalize the storefront in real time based on the user location and behavior.

What are Medusa Modules?

Modules are packages with self-contained commerce logic, promoting separation of concerns, maintainability, and reusability. Modules increase Medusa's extensibility, allowing for customization of core commerce logic and composition with other tools. This flexibility allows for greater choice in the tech stack used in conjunction with Medusa.

Prerequisites

The Product Module must connect to a PostgreSQL database. You can refer to this guide to learn how to install PostgreSQL locally. Alternatively, you can use free PostgreSQL database hosting, such as Vercel Postgres. If you have an existing Medusa database, you can use it as well.

Get started

To run the demo locally, follow these steps:

Step 1. Clone this repo and install the dependencies.

In the project root, run:

npm install

or

yarn

Step 2: Add Database Configurations

Create a .env file and add the following environment variable:

POSTGRES_URL=<DATABASE_URL>

Where <DATABASE_URL> is your database connection URL of the format postgres://[user][:password]@[host][:port]/[dbname]. You can learn more about the connection URL format in this guide.

Step 3: Run Database Migrations and seed the Database

npm run product:migrations:run
# optionally
npm run product:seed

or

yarn product:migrations:run
# optionally
yarn product:seed

Step 4: Run the app locally

Run the app with npm run dev or yarn dev.