Maciej Łopalewski
Maciej Łopalewski
Senior Software Engineer

Boost Your Medusa E-Commerce Development: Streamlined Local Setup Guide

May 22, 20253 min read

Medusa is a powerful open-source headless commerce engine that provides a flexible and robust foundation for building e-commerce applications. Getting started with a new framework often involves setting up various prerequisites and understanding configuration nuances. While the official documentation is excellent, having a pre-configured starting point can significantly accelerate the local development process.

This article will guide you through setting up Medusa locally, focusing on common requirements and helpful configurations. We'll also introduce a specific resource, the medusa-starter repository, designed to simplify these initial steps and provide valuable examples for future deployment.

The Standard Medusa Installation Path

The official Medusa documentation offers comprehensive guides for getting started. You can find the detailed installation instructions covering prerequisites like Node.js, PostgreSQL, and Redis on the Medusa Installation guide. It's highly recommended to familiarize yourself with these official steps.

Simplifying Prerequisites with medusa-starter

One of the initial hurdles in setting up a local development environment for Medusa is provisioning the necessary database (PostgreSQL) and caching layer (Redis). The medusa-starter repository addresses this by providing a simple Docker Compose file specifically for these services.

Within the repository, you'll find a compose.db.yaml file (link to compose.db.yaml). This file allows you to spin up ready-to-use PostgreSQL and Redis instances with a single command:

docker-compose -f compose.db.yaml up -d

This command brings up the necessary services in detached mode (-d), allowing you to quickly get your database and cache dependencies running without manual installation and configuration. Based on the configuration in compose.db.yaml, this will set up:

  • PostgreSQL: Available on localhost:5432. It will be configured with the user, password, and database name specified within the compose file or corresponding environment variables, ready for your Medusa instance to connect.
  • Redis: Available on localhost:6379. For this local development setup, authentication is typically not required, allowing for straightforward connection.

The medusa-starter repository includes environment variables tailored to connect to these services, making integration straightforward once they are running.

Understanding NODE_ENV and Its Implications

A critical aspect of configuring your Medusa application, both locally and in production, is the NODE_ENV environment variable. This variable significantly influences Medusa's behavior.

  • NODE_ENV=development: This is the standard setting for local development. In this mode, Medusa often provides more detailed logging and error messages, and certain security constraints are relaxed to facilitate rapid iteration.
  • NODE_ENV=production: This setting is intended for production deployments. Medusa enables stricter security measures and optimizes for performance. A key behavior change in production mode is the requirement for a secure connection (HTTPS/TLS) and a custom domain to access the Medusa Admin panel. This is because Medusa uses secure cookies for authentication, which browsers will only send over a secure connection to a specific domain, not localhost.

A NODE_ENV Workaround for Local Docker (Without TLS)

If you are trying to run your Medusa application locally within a Docker container without setting up TLS and a custom domain, using NODE_ENV=production will prevent you from logging into the admin panel.

As a workaround for this specific scenario (local Docker testing without TLS), you can set NODE_ENV to a different value, such as CI. While this allows you to bypass the secure cookie requirement locally, it is important to understand that this is a workaround and not a recommended practice for actual production deployments. For production, always use NODE_ENV=production and ensure proper TLS setup.

Beyond Local Development: Production Examples in medusa-starter

The medusa-starter repository isn't just for getting started locally. It also provides valuable examples to help you transition towards production deployments:

  • medusa-config.ts Example: The repository includes an example medusa-config.ts file (link to medusa-config.ts) that demonstrates how to configure modules and settings suitable for a production environment, often integrating with the Docker Compose database setup.
  • Example Dockerfiles: You'll find example Dockerfiles (link to Dockerfiles) that show you how to package your Medusa application into a Docker image, a common step for cloud deployments.
  • Example GitHub Actions Workflow: The repository includes a basic GitHub Actions workflow example (link to GitHub Actions) that you can adapt for your own projects. This workflow demonstrates a basic Continuous Integration (CI) pipeline, which is crucial for automating testing and building your application.

Conclusion

Setting up a development environment can sometimes feel like the first significant hurdle. The medusa-starter repository (v2) aims to lower that barrier by providing pre-configured examples for essential services via Docker Compose. By understanding the role of NODE_ENV and leveraging the provided configuration and Docker examples, you can not only streamline your local development workflow but also gain a head start on preparing your Medusa application for production deployment. Explore the repository, adapt the examples to your needs, and happy coding 👨‍💻✨!

RELATED POSTS
Daniel Kraszewski
Daniel Kraszewski
Head of Engineering

Exposing Private Load Balancers with CloudFront VPC Origins

Apr 30, 20254 min read
Article image
Michał Miler
Michał Miler
Senior Software Engineer

Passing Dynamic Environment Variables Between GitLab CI Matrix Jobs: AWS OIDC Example

Apr 09, 20254 min read
Article image
Michał Miler
Michał Miler
Senior Software Engineer

Sharing Artifacts Between GitLab CI Matrix Jobs: React Build Example

Apr 02, 20253 min read
Article image