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.
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.
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.
To run the demo locally, follow these steps:
In the project root, run:
npm install
or
yarn
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.
npm run product:migrations:run
# optionally
npm run product:seed
or
yarn product:migrations:run
# optionally
yarn product:seed
Run the app with npm run dev
or yarn dev
.