Medusa Configuration in Details | Medusa Development Course

By Viktor Holik

Featured image

Welcome to our Medusa Development Course! In this series, you'll learn how to get your development environment ready and take your first steps in building a Medusa-powered e-commerce application. We'll walk you through everything step by step, helping you master Medusa’s modular architecture and build the key features you need.

This course was made by Viktor Holik, our Software Engineer and Medusa Expert.

In this episode of our course, we’ll talk about medusa-config.js a little bit more, including environment variables, plugins, modules, configurations, and featureFlags.

Medusa Configuration in Details

You can find the transcription of the guide below.

Let's talk about medusa-config.js a little bit more.

I will start with the environment variables. Here we have this case, and it's changing the ENV-FILE-NAME property based on the NODE_ENV that is provided in the environment variables.

Let's create a new file named .env.staging and move the database URL property over there. Cool.

Now let's go into the package.json and add this NODE_ENV property as "staging." Cool.

Let's console log the ENV-FILE-NAME and make sure that the ENV-FILE-NAME is proper. Now, if we run the yarn dev command, we would see .env.staging in the console, as you can see.

On line 21, dotenv.config reads the environment variables based on the ENV-FILE-NAME.

We also have ADMIN_CORS and STORE_CORS, which are responsible for handling store configuration for the storefront and admin panel. We also have the REDIS_URL and the DATABASE_URL.

Now let's talk about Medusa plugins. As you can see here, we have Medusa.js admin added as a plugin, and we can disable or enable it based on our choice.

I also want to highlight that Medusa has a powerful community, and the community creates new plugins like payment plugins, integrations with shipping, search integrations, storage, and others, like analytics.

You can also create your own plugins, but we will cover that in the next module.

Now let's talk about modules. In Medusa, certain logic like the event bus system or cache that can be replaced and it's modularized for its reusability. So, if you don’t want to use Redis for the cache system, you can build your own cache service, and Medusa will use it.

In the development phase, you can comment them out, but when you deploy and go to production, it is recommended to use them to prevent memory leaks.

You also have the JWT_SECRET, which is used for generating JWTs, and the cookie secret, which is used for generating cookies. We also have STORE_CORS, DATABASE_URL, and ADMIN_CORS, that we have seen. You also have the REDIS_URL, which we should uncomment in production.

If you want to see the full list of configurations in a medusa-config.js file, you should definitely check out the configurations page in the Medusa documentation.

Now let's talk about featureFlags in Medusa. So, Medusa comes with features that can be enabled or disabled. Some of them are enabled by default, like order editing, so by default you can change order details.

You also have some additional featureFlags, such as Tax-Inclusive Pricing, to change the tax behavior from exclude to include. And also some additional, like Sales Channels and Publishable API Keys, which are enabled by default.

Let's enable some disabled featureFlag, for example, product categories. To do that, we can change MEDUSA_FF_PRODUCT_CATEGORIES to true in the environment variables and start our project.

Now, if we log into the admin panel, we can add some categories, and even more - we can add multiple subcategories.

In short

That’s it for mastering configuration options in Medusa! With the knowledge you’ve gained, you can now fine-tune your store and customize the platform.

In the next episode, we'll harness the power of Medusa's dependency injection system.

We hope you found Viktor's tutorial insightful and helpful.

Learn how to create a customizable commerce solutions

Check out our Medusa Development Course on YouTube

Other blog posts

Admin Development | Medusa Development Course

Welcome to our Medusa Development Course! Build the user interface for managing suppliers and updating product suppliers in Medusa’s admin panel.

Subscribers | Medusa Development Course

Welcome to our Medusa Development Course! Create and customize subscribers to respond to key events, like sending an email when an order is placed.

Tell us about your project

Got a project in mind? Let's make it happen!

placeholder

Grzegorz Tomaka

Co-CEO & Co-founder

LinkedIn icon
placeholder

Jakub Zbaski

Co-CEO & Co-founder

LinkedIn icon