Next.js Starter Storefront
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.
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.
- From the root of your monorepo, clone the DTC Starter into a temporary directory to extract the storefront:
- Copy the storefront into your project's
appsdirectory, then remove the temporary clone:
- Make sure your workspace configuration includes the
apps/storefrontdirectory. If yourpnpm-workspace.yamlor theworkspacesfield inpackage.jsonalready uses a glob likeapps/*, no change is needed. Otherwise, add it explicitly:
- From the monorepo root, install the dependencies:
- Create the storefront's environment file from its template:
- 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:
NEXT_PUBLIC_MEDUSA_BACKEND_URL=http://localhost:9000
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_123...
- While the Medusa application is running, start the Next.js Starter storefront from the
apps/storefrontdirectory:
Your Next.js Starter storefront is now running at http://localhost:8000.
- To deploy the storefront to Cloud, commit and push the
apps/storefrontdirectory to your project's repository. Then, add the storefront to your Cloud project withapps/storefrontas its root directory. Cloud sets the storefront's backend URL and publishable API key, so you don't addNEXT_PUBLIC_MEDUSA_BACKEND_URLorNEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEYto 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:
Where <YOUR_PUBLISHABLE_KEY> is your Stripe publishable key. Then, restart the Next.js Starter storefront. You can now use Stripe during checkout.
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:
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: