Next.js Starter Storefront

Note: Since Medusa v2.14.0, the Next.js Starter storefront is part of a monorepo with the Medusa application. The standalone Next.js Starter Storefront is now deprecated.

The Medusa application is made up of a Node.js server and an admin dashboard. The storefront is hosted separately from the Medusa application. You have the flexibility to choose the frontend tech stack that you and your team are proficient in, and implement unique design systems and user experience.

The Next.js Starter Storefront is a good place to start building your storefront. It provides rich commerce features and a sleek design. Developers and businesses can use it as-is or build on top of it to tailor it for the business's unique use case, design, and customer experience.

Note: This guide helps technical users set up the Next.js Start storefront. If you're not a technical user, refer your technical team to this documentation instead.

Installation#

Approach 1: Create a Cloud Project#

The Blank DTC starter on Cloud includes the Medusa application and the Next.js Starter storefront. To create a project from it, follow the Create Your First Project guide.

Cloud clones the starter into a GitHub repository in your account or organization, then deploys both the Medusa application and the storefront. It also sets the storefront's backend URL, publishable API key, and CORS settings for every environment. Learn more in the Storefront Deployment guide.

Then, to customize the storefront, set up the project on your machine by following the Set Up Medusa Locally guide. The Medusa backend is in the apps/backend directory, and the Next.js Starter storefront is in the apps/storefront directory. Locally, the storefront runs at http://localhost:8000.

Approach 2: Add to an Existing Project#

If you already have a Medusa monorepo installed and want to add the Next.js Starter storefront to it, follow these steps.

  1. From the root of your monorepo, clone the DTC Starter into a temporary directory to extract the storefront:
Terminal
git clone https://github.com/medusajs/dtc-starter.git --depth=1 dtc-temp
  1. Copy the storefront into your project's apps directory, then remove the temporary clone:
Terminal
cp -r dtc-temp/apps/storefront apps/storefront
rm -rf dtc-temp
  1. Make sure your workspace configuration includes the apps/storefront directory. If your pnpm-workspace.yaml or the workspaces field in package.json already uses a glob like apps/*, no change is needed. Otherwise, add it explicitly:
pnpm-workspace.yaml
packages:
  - 'apps/*'
  1. From the monorepo root, install the dependencies:
  1. Create the storefront's environment file from its template:
Terminal
cp apps/storefront/.env.template apps/storefront/.env.local
  1. In apps/storefront/.env.local, set the URL of your Medusa backend and your publishable API key. You can retrieve the publishable API key from the Medusa Admin dashboard by going to Settings > Publishable API Keys:
apps/storefront/.env.local
NEXT_PUBLIC_MEDUSA_BACKEND_URL=http://localhost:9000
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_123...
  1. While the Medusa application is running, start the Next.js Starter storefront from the apps/storefront directory:

Your Next.js Starter storefront is now running at http://localhost:8000.

  1. To deploy the storefront to Cloud, commit and push the apps/storefront directory to your project's repository. Then, add the storefront to your Cloud project with apps/storefront as its root directory. Cloud sets the storefront's backend URL and publishable API key, so you don't add NEXT_PUBLIC_MEDUSA_BACKEND_URL or NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY to its environment variables.

Troubleshooting#

CORS Error
Resolve "Cannot find module X" Errors
Issues when installing with Node v25+

Payment Providers#

Stripe Integration#

The Next.js Starter storefront is compatible with Medusa's Stripe Module Provider.

The storefront reads your Stripe publishable key from the NEXT_PUBLIC_STRIPE_KEY environment variable. You can retrieve the key from your Stripe dashboard by going to Developers → API Keys.

On Cloud, add NEXT_PUBLIC_STRIPE_KEY in the environment's Storefront variables, and enable its Build toggle, since Next.js includes it in the storefront's build. Then, redeploy the environment. Learn more in the Environment Variables Cloud guide.

Locally, set the variable in apps/storefront/.env.local:

Terminal
NEXT_PUBLIC_STRIPE_KEY=<YOUR_PUBLISHABLE_KEY>

Where <YOUR_PUBLISHABLE_KEY> is your Stripe publishable key. Then, restart the Next.js Starter storefront. You can now use Stripe during checkout.

Tip: Refer to this guide to learn how to customize the Stripe integration and components.

Change Medusa Application URL#

The Next.js Starter storefront reads the URL of the Medusa application from the NEXT_PUBLIC_MEDUSA_BACKEND_URL environment variable.

On Cloud, Medusa sets this variable to the URL of the environment's Medusa application, so you don't need to set it. Learn more in the Storefront Deployment guide.

Locally, the Medusa application runs at http://localhost:9000 by default. To change the URL of the Medusa application in the storefront, set the NEXT_PUBLIC_MEDUSA_BACKEND_URL environment variable in apps/storefront/.env.local:

apps/storefront/.env.local
NEXT_PUBLIC_MEDUSA_BACKEND_URL=https://example.com

Change Medusa Publishable API Key#

All requests made from a storefront must pass a publishable API key in the request's header. This API key is created in the Medusa application.

On Cloud, Medusa sets the NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY environment variable to a publishable API key of the environment's Medusa application, so you don't need to set it.

Locally, if you change your Medusa application or its database, or you lose the publishable API key you had before, change the NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY environment variable in apps/storefront/.env.local to the new publishable API key:

Terminal
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_123...
Was this page helpful?
Docs Assistant
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵