OneStopList

Gods and goddesses

Medusa 4 Tutorial: Step-by-Step Guide for Beginners

Updated November 25, 2026

This tutorial explains how to use Medusa 4, the fourth major release of the open-source Medusa e-commerce platform, covering installation, core concepts, and common customization tasks. Medusa 4 is a headless commerce engine built with Node.js and TypeScript, designed for developers who want to build custom storefronts, marketplaces, or subscription services without the constraints of traditional monolithic platforms.

What Is Medusa 4 and Why Use It?

Medusa is an open-source headless commerce platform that provides the backend for online stores—handling products, orders, customers, and payments—while letting you build the frontend with any technology (React, Vue, Next.js, etc.). Version 4, released in 2024, introduced a modular architecture, a new admin dashboard, and improved performance. Unlike Shopify or WooCommerce, Medusa is self-hosted, meaning you control your data and can modify every part of the system. It’s particularly popular for developers who need custom business logic, such as multi-vendor marketplaces or B2B pricing, because you can extend the core with plugins and custom endpoints.

Prerequisites and Installation

Before you start, you need Node.js (version 18 or higher) and a package manager like npm or yarn. You also need a PostgreSQL database (version 13 or higher) and Redis for caching and background jobs. Here’s a quick setup:

  • Install the Medusa CLI globally: npm install -g @medusajs/medusa-cli
  • Create a new project: medusa new my-store --template start
  • Navigate to the project folder and configure your environment variables in .env (database URL, Redis URL, etc.)
  • Run migrations and seed data: medusa migrations run and medusa seed --seed-file data/seed.json
  • Start the development server: medusa develop

The default admin dashboard runs at http://localhost:7000, and the API is at http://localhost:9000. You can test the API with tools like Postman or curl.

Core Concepts: Regions, Sales Channels, and Stock Locations

Medusa 4 uses several key abstractions that you need to understand before building your store:

  • Regions: Define a geographical area with its own currency, payment providers, and shipping options. For example, you can have a ‘US’ region with USD and a ‘EU’ region with EUR.
  • Sales Channels: Group products and orders for different sales contexts, like an online store and a physical POS. You can assign products to specific channels.
  • Stock Locations: Manage inventory across multiple warehouses. Each location has its own stock levels, and you can set up fulfillment providers to handle shipping from each.

These concepts allow you to run a global store with localized pricing and shipping, or a multi-warehouse operation, all from one backend.

Creating Products and Managing Inventory

To add a product, you can use the admin dashboard or the API. A product has a title, description, images, and one or more variants (e.g., size, color). Each variant has its own SKU, price, and inventory. Here’s a typical workflow:

  1. Go to the admin dashboard and click ‘Products’ → ‘Create New’.
  2. Enter the product details, upload images, and set a price for each region.
  3. Add variants by specifying options like ‘Size’ and ‘Color’. For each variant, set a SKU and price.
  4. Manage inventory by going to ‘Inventory’ and updating stock levels for each variant and location.

You can also import products via CSV using the built-in importer, which speeds up bulk uploads.

Setting Up Payments and Shipping

Medusa supports multiple payment providers via plugins. The default setup includes Stripe and PayPal, but you can install others like Klarna or Adyen. To configure Stripe:

  • Install the Stripe plugin: npm install medusa-payment-stripe
  • Add your Stripe secret key to .env and enable the provider in the admin under Settings → Payment.
  • For shipping, you can use the built-in manual provider or integrate with carriers like FedEx or ShipStation via plugins. You define shipping options per region, with pricing and requirements (e.g., minimum order value).

Test payments in sandbox mode before going live.

Customizing with Plugins and Extensions

One of Medusa 4’s strengths is its plugin system. You can extend the core by creating your own plugins or using community ones. For example, you can add a custom endpoint to handle a unique business rule, or create a plugin that integrates with a third-party ERP. The architecture uses a service layer, so you can override existing services. To create a plugin, use the CLI: medusa new my-plugin --template plugin. Then, in your main project, add it to medusa-config.js under the plugins array. You can also use the admin dashboard’s ‘Customizer’ to add custom fields to products and orders without coding.

Common Problems and Troubleshooting

New users often encounter a few issues:

  • Database connection errors: Ensure PostgreSQL is running and the DATABASE_URL is correct. Check that the user has privileges.
  • Redis connection issues: Redis is used for sessions and caching; if it’s not running, you’ll see errors. Start it with redis-server or use a managed service.
  • Port conflicts: The default ports (9000 and 7000) might be occupied. Change them in .env.
  • Seed data not loading: Make sure you run medusa migrations run before seeding.

If you get a 404 on API routes, check that the server is running and the route is correct. The official documentation has a troubleshooting section.

Comparison with Other Platforms

Medusa 4 is often compared to other headless commerce solutions:

  • Medusa vs. Shopify: Shopify is easier to set up but less customizable. Medusa is free (open-source) but requires hosting and development effort.
  • Medusa vs. Saleor: Both are open-source, but Saleor uses GraphQL and a different architecture. Medusa uses REST and has a more modular plugin system.
  • Medusa vs. Spree: Spree is Ruby-based, while Medusa is Node.js. Medusa has a more modern developer experience for JS developers.

Choose Medusa if you need full control and are comfortable with Node.js.

Costs and Hosting Considerations

Medusa itself is free, but you’ll pay for hosting, database, Redis, and third-party services. A typical setup on a VPS (e.g., DigitalOcean) might cost $20–$50 per month for small stores. You can also use managed services like Railway or Heroku, which simplify deployment. Remember to factor in payment gateway fees (e.g., Stripe charges per transaction) and any premium plugins you might purchase. For production, you should set up SSL, monitoring, and backups.

Frequently Asked Questions

Q: Do I need to know TypeScript to use Medusa 4?
Yes, Medusa is written in TypeScript, and while you can use JavaScript, most documentation and examples are in TypeScript. Basic knowledge is required.

Q: Can I migrate from Medusa 3 to Medusa 4?
There is a migration guide in the official docs. It involves updating dependencies and adjusting configuration, but it’s not automatic. Plan for downtime.

Q: How do I add a custom product field?
You can use the admin’s Customizer to add fields without code. For more complex logic, create a plugin that extends the product entity.

Q: Is Medusa suitable for non-developers?
Not really. It’s a developer tool. If you don’t code, consider a hosted solution like Shopify.

Q: Can I use Medusa with a mobile app?
Yes, the API is RESTful, so you can connect any frontend, including React Native or Flutter apps.

Q: What payment providers are supported?
Stripe, PayPal, and Klarna are official plugins, but you can build your own provider if needed.

By following this tutorial, you should have a working Medusa 4 store and understand its core concepts. For deeper dives, refer to the official documentation and community forums.

Related

How pages are sourced and corrected: Sources and editorial policy.