(non) Tech Self Notes / Medusa.js setup

Medusa.js Setup on Ubuntu

Medusa links:

It requires:

And its recommended to use

Install all these componetns beforehead.

To install PostgreSQL:

Refer to: https://wiki.archlinux.org/title/PostgreSQL

To the .env file add a string (the only string for the PostgreSQL configuration) like:


DATABASE_URL=postgres://medusa-user:medusa_db_pass@localhost/medusa-database`

To install medusa.js do:

npx create-medusa-app@latest my-medusa-store --with-nextjs-starter

To setup redis modules do:

Add to .env file variables:


REDIS_URL=redis://localhost:6379`
EVENTS_REDIS_URL=redis://localhost:6379`
CACHE_REDIS_URL=redis://localhost:6379`
LOCKING_REDIS_URL=redis://localhost:6379`

Add to yor medusa-config.ts:

The medusa-config.ts file should be like this after that:


import { loadEnv, defineConfig } from '@medusajs/framework/utils'

loadEnv(process.env.NODE_ENV || 'development', process.cwd())

module.exports = defineConfig({
  projectConfig: {
    databaseUrl: process.env.DATABASE_URL,
    redisUrl: process.env.REDIS_URL,
    http: {
      storeCors: process.env.STORE_CORS!,
      adminCors: process.env.ADMIN_CORS!,
      authCors: process.env.AUTH_CORS!,
      jwtSecret: process.env.JWT_SECRET || "supersecret",
      cookieSecret: process.env.COOKIE_SECRET || "supersecret",
    }
  },

modules: [
    {
      resolve: "@medusajs/medusa/cache-redis",
      options: {
        redisUrl: process.env.REDIS_URL,
      },
    },
    {
      resolve: "@medusajs/medusa/event-bus-redis",
      options: {
        redisUrl: process.env.REDIS_URL,
      },
    },
    {
      resolve: "@medusajs/medusa/locking",
      options: {
        providers: [
          {
            resolve: "@medusajs/medusa/locking-redis",
            id: "redis-lock",
            is_default: true,
            options: {
              redisUrl: process.env.LOCKING_REDIS_URL,
            }
          },
        ]
      }
    }

  ],
})

Generate two secrets:

openssl rand -hex 32 for JWT_SECRET and COOKIE_SECRET and supply these values in the .env file:


JWT_SECRET=<paste here the one>
COOKIE_SECRET=<paste here another>

To build store front:

Exclude unnesessary locales. Insert the snippet to the file <medusa-storefront>/src/app/[countryCode]/\(main\)/categories/[...category]/ between const countryCodes and const countryHandles function:


  if (process.env.LIMIT_BUILD_LANGS === 'true') {
    countryCodes = countryCodes.filter((code) => ['en','ru','he'].includes(code))

    // countryCodes = countryCodes.filter((code) => !['it', 'ru'].includes(code)) // for leaving only nessessary locales
  }

To build backend:

from https://docs.medusajs.com/resources/medusa-cli/commands/build

In the backend folder run npx medusa build. Then cd .medusa/server and install dependencies: npm install.

When running the application locally, make sure to copy the .env file from the root project’s directory. In production, use system environment variables instead: cp .env .medusa/server/.env.production

In the system environment variables, set NODE_ENV to productionCopy: NODE_ENV=production

Use the start command to run the application: cd .medusa/server && npm run start

toDo: to resolve problem with admin panel login: 401 unauthorized.

debug: Skipping auth GET /admin/users/me

{
"level":"http",
"client_ip":"::ffff:192.168.88.253",
"request_id":"a40a6ba5-3a24-426e-89f2-ad814ce58740",
"http_version":"1.1",
"method":"GET",
"path":"/admin/users/me",
"status":401,
"response_size":"26",
"request_size":0,
"duration":1.365,
"referrer":"http://192.168.88.17:9000/app",
"user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
"timestamp":"2025-03-25T17:50:04.361Z"
}