### Install Medusa Application using create-medusa-app Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Installs a new Medusa application project on your machine using the `create-medusa-app` CLI tool. This command initiates the setup process, prompting for project details and optionally installing a starter storefront. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Install Medusa Application and Storefront - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command initializes a new Medusa project using the latest version of `create-medusa-app`. It sets up the core headless server and optionally installs a Next.js storefront, which is required for this integration guide. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Start Medusa Application (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Initiate the Medusa application where the plugin is installed. This command starts the development server, making the application accessible. ```Bash npm run dev ``` -------------------------------- ### Define Start Command for Medusa Production Server Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Sets the production start command for the Medusa server application. It changes the current directory to the build output (`.medusa/server`), installs dependencies, runs the `predeploy` script (for migrations and link syncing), and finally starts the server. ```bash cd .medusa/server && npm install && npm run predeploy && npm run start ``` -------------------------------- ### Starting Medusa Application Development Server (npm) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Start the development server for your Medusa application. With the plugin installed and being watched, you can now test your plugin's functionality within the running Medusa application. ```bash npm run dev ``` -------------------------------- ### Example Response from Medusa Brands API (JSON) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Shows an example JSON response structure returned by the `/admin/brands` GET API route, illustrating how brands are returned with their nested product data. ```JSON { "brands": [ { "id": "123", // ... "products": [ { "id": "prod_123", // ... } ] } ] } ``` -------------------------------- ### Starting Built Medusa Application - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Navigates into the built application directory (.medusa/server) and starts the Medusa server using the start script defined in the package.json. This runs the production build. ```bash cd .medusa/server && npm run start ``` -------------------------------- ### Installing Dependencies for Built Medusa Server Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Navigates into the built server directory (`.medusa/server`) and installs the necessary Node.js dependencies using npm. This step is required before starting the built application. ```bash cd .medusa/server && npm install ``` -------------------------------- ### Installing Medusa Application Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Use the npx command to initialize a new Medusa project. This command will prompt you for project details and offer to install a starter storefront. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Installing Medusa Application (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command uses `npx` to execute the `create-medusa-app` package, initiating the installation process for a new Medusa e-commerce application. It prompts the user for a project name and optionally allows installing a starter storefront. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Install Medusa Application using npx Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command initializes a new Medusa project. It requires Node.js v20+, Git, and PostgreSQL. The command will prompt for a project name and whether to install the Next.js storefront, creating the necessary directories and installing dependencies. ```bash npx create-medusa-app@latest ``` -------------------------------- ### start Command - Medusa CLI Reference Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Start the Medusa application in production mode. Includes options for host, port, and enabling cluster mode. ```bash npx medusa start ``` -------------------------------- ### Start Built Medusa Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Navigates to the built server directory (`.medusa/server`) and executes the `start` script defined in its `package.json`. This command initiates the Medusa server process. ```bash cd .medusa/server && npm run start ``` -------------------------------- ### Install Medusa Application - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Use this command to install a new Medusa application on your machine. It requires Node.js v20+, Git CLI, and PostgreSQL. The command prompts for a project name and optionally allows installing a Next.js starter storefront. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Starting Development Servers (Medusa & Storefront) in Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides the bash commands to start the Medusa backend and the Next.js storefront development servers. This is necessary to test the implemented search feature locally. ```bash npm run dev ``` ```bash yarn dev ``` -------------------------------- ### Starting Next.js Storefront (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Run this command in the storefront's directory to start the Next.js development server, allowing you to view and interact with the storefront and test localized content. ```bash npm run dev ``` -------------------------------- ### Starting Medusa Application (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Run this command in the Medusa application's directory to start the development server and test the implemented changes, such as localized product details. ```bash npm run dev ``` -------------------------------- ### Starting Medusa Development Server Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Use this command to start the Medusa application in development mode, which is required before testing API endpoints. ```bash npm run dev ``` -------------------------------- ### Run Vale Linting Script Locally (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides examples of how to execute the `run-vale.sh` script from the `www/vale` directory to lint different sections of the Medusa documentation locally. Includes commands for main docs, resources, API reference, UI docs, and user guide. ```bash ./run-vale.sh book/app/learn error resources # to lint content for the resources documentation ./run-vale.sh resources/app error # to lint content for the API reference ./run-vale.sh api-reference/markdown error # to lint content for the Medusa UI documentation ./run-vale.sh ui/src/content/docs error # to lint content for the user guide ./run-vale.sh user-guide/app error ``` -------------------------------- ### Starting the Medusa Application (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command starts the Medusa development server, which is necessary to test scheduled jobs and other customizations. ```Bash npm run dev ``` -------------------------------- ### Install Medusa Application using create-medusa-app Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Installs the Medusa application and optionally a Next.js storefront using the `create-medusa-app` CLI tool. This command sets up the basic project structure. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Starting Medusa Application to Test Module Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Run this command in your terminal to start the Medusa application and trigger the Contentful module's loader. ```bash npm run dev ``` -------------------------------- ### Start Medusa Development Server Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Starts the Medusa application in development mode, typically enabling API routes and other services for testing. ```bash npm run dev ``` -------------------------------- ### Start Medusa Development Server - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Executes the command to start the Medusa application in development mode, making the API routes, including the Contentful webhook listener, available for testing. ```bash npm run dev ``` -------------------------------- ### Starting Medusa Development Server Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Medusa application in development mode, which is necessary to test custom API routes and run CLI scripts. ```Bash npm run dev ``` -------------------------------- ### Starting Medusa Development Server with npm Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Medusa application in development mode using npm. This is used to test the created subscriber by triggering events. ```Bash npm run dev ``` -------------------------------- ### Starting Medusa Application - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command starts the Medusa application in development mode. This is necessary to access the Medusa Admin dashboard and test the newly created UI route and sync functionality. ```Bash npm run dev ``` -------------------------------- ### Start Next.js Storefront (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Executes the `npm run dev` command in the Next.js Starter Storefront directory to start the frontend application in development mode, typically running on `http://localhost:8000`. ```bash npm run dev ``` -------------------------------- ### Example JSON Response for Created Post Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This is an example of the JSON response returned by the `/blog/posts` API endpoint after successfully creating a blog post via the workflow. ```json { "post": { "id": "123...", "title": "My Post", "created_at": "...", "updated_at": "..." } } ``` -------------------------------- ### Starting Medusa Development Server Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command starts the Medusa application in development mode, typically watching for file changes and restarting the server. ```bash npm run dev ``` -------------------------------- ### Start Medusa Development Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Medusa application in development mode, which is necessary to test the subscriber and API routes. ```Bash npm run dev ``` -------------------------------- ### Start Next.js Storefront Dev Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Next.js storefront application in development mode. Execute this command in the root directory of your storefront project to run the client locally. ```Bash npm run dev ``` ```Bash yarn dev ``` -------------------------------- ### Start Medusa Backend (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Executes the `npm run dev` command in the Medusa backend directory to start the application in development mode, making the API available. ```bash npm run dev ``` -------------------------------- ### Starting Built Medusa Application in Production Mode Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Sets the `NODE_ENV` environment variable to `production` and then starts the built Medusa application from the `.medusa/server` directory using `npm run start`. This ensures the application runs in production mode and loads production environment variables. ```bash export NODE_ENV=production npm run start ``` -------------------------------- ### Start Medusa Development Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command starts the Medusa backend application in development mode. It is necessary to have the backend running for the storefront and scheduled jobs to interact with it. ```Bash npm run dev ``` -------------------------------- ### Start Medusa Development Server - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Starts the Medusa application in development mode, enabling testing of new features like sending quotes or accessing customer preview endpoints. ```bash npm run dev ``` -------------------------------- ### Start Medusa Development Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides the command to start the Medusa application in development mode. This is necessary to test the implemented API routes and middlewares locally. ```bash npm run dev ``` -------------------------------- ### Install Medusa Application with Next.js Storefront Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command initializes a new Medusa project, including the headless server and optionally the Next.js starter storefront. It sets up the basic project structure and installs necessary dependencies. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Set Medusa Worker Start Command in Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides a start command for deploying the Medusa application in worker mode when the hosting provider doesn't support setting a current working directory. It navigates to the build output, installs dependencies, and starts the server. ```Bash cd .medusa/server && npm run install && npm run start ``` -------------------------------- ### Starting Medusa Development Server (bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Medusa application in development mode, typically used for testing API routes and the admin dashboard. ```bash npm run dev ``` -------------------------------- ### Starting Medusa Development Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command starts the Medusa application in development mode. It is used here to test the tracing feature by generating activity that will be reported to a configured exporter like Zipkin. ```bash npm run dev ``` -------------------------------- ### Installing Medusa Application with create-medusa-app (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command uses `npx` to execute the `create-medusa-app` package, initiating the installation process for a new Medusa project. It sets up the core Medusa server and optionally a starter storefront like Next.js. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Start Medusa Application (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Run this command in your terminal from the root of your Medusa project to start the application. This process will trigger the execution of all configured module loaders. ```Bash npm run dev ``` -------------------------------- ### Starting Medusa Application (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This bash command is used to start the Medusa application in development mode. This allows testing the newly created UI routes and API endpoints locally. ```bash npm run dev ``` -------------------------------- ### Start Medusa Application (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Medusa application in development mode. This is required to test the custom UI route by accessing it in the browser. ```bash npm run dev ``` ```bash yarn dev ``` -------------------------------- ### Installing Dependencies for Built Medusa App - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Navigates into the built application directory (.medusa/server) and installs production dependencies using npm. This is a necessary step before running the built application. ```bash cd .medusa/server && npm install ``` -------------------------------- ### Starting Medusa Development Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Executes the command to start the Medusa application in development mode, typically used for testing UI changes and API routes. ```bash npm run dev ``` -------------------------------- ### Start Next.js Development Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to execute in the terminal to start the development server for the Next.js storefront. This server needs to be running to access the Sanity studio at the /studio path. ```Bash npm run dev ``` -------------------------------- ### Starting Next.js Storefront Development Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This bash command is used to start the Next.js storefront application in development mode. It runs the development server, making the storefront accessible locally. ```Bash npm run dev ``` -------------------------------- ### Starting the Medusa Application (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Medusa application in development mode. This is necessary to test custom admin widgets or UI routes by running the local server. ```bash npm run dev ``` -------------------------------- ### Install Medusa Application - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Use this command to initialize a new Medusa application project. It utilizes the `create-medusa-app` tool to set up the core Medusa server and optionally a starter storefront. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Test Shared Wishlist GET API Route (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides a `curl` command example to test the newly created GET API route for retrieving a shared wishlist. It demonstrates how to send a GET request to the `/store/wishlists/:token` endpoint, including the wishlist token in the URL path and the publishable API key in the `x-publishable-api-key` header. ```Bash curl 'localhost:9000/store/wishlists/{wishlist_token}' \ --header 'x-publishable-api-key: {api_key}' ``` -------------------------------- ### Start Medusa Application (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command used to start the Medusa application in development mode. This is done to test if the configured module initializes correctly and connects to its external service. ```Bash npm run dev ``` -------------------------------- ### Accessing Query Parameters in Medusa GET Route (TypeScript) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This TypeScript snippet demonstrates how to access query parameters from the `MedusaRequest` object within a GET route handler. The `req.query` property provides an object containing key-value pairs of the query parameters. This example retrieves the value of the 'name' query parameter. ```typescript import type { MedusaRequest, MedusaResponse, } from "@medusajs/framework/http" export const GET = async ( req: MedusaRequest, res: MedusaResponse ) => { res.json({ message: `Hello ${req.query.name}`, }) } ``` -------------------------------- ### Setup Medusa Database (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Executes the `db:setup` command via `npx medusa`. This command creates a database if it doesn't exist, runs all pending migrations, syncs link definitions, and updates the `.env` file with the database name. Requires the `--db` option. ```bash npx medusa db:setup --db ``` -------------------------------- ### Installing Medusa Plugin Locally (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Execute this command in the Medusa application's directory to install the plugin from the local package registry. This integrates the plugin into the application for testing. ```bash npx medusa plugin:add medusa-plugin-wishlist ``` -------------------------------- ### Defining GET and POST Handlers for a Medusa API Route (TypeScript) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Shows how to define handler functions for specific HTTP methods (`GET` and `POST` in this example) within a route file (`src/api/hello-world/route.ts`). Each exported function corresponds to an allowed HTTP method and will handle requests sent to that method at the route path. ```ts import type { MedusaRequest, MedusaResponse, } from "@medusajs/framework/http" export const GET = async ( req: MedusaRequest, res: MedusaResponse ) => { res.json({ message: "[GET] Hello world!", }) } export const POST = async ( req: MedusaRequest, res: MedusaResponse ) => { res.json({ message: "[POST] Hello world!", }) } ``` -------------------------------- ### Start Medusa Backend Dev Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Medusa backend application in development mode. Execute this command in the root directory of your Medusa project to run the server locally. ```Bash npm run dev ``` ```Bash yarn dev ``` -------------------------------- ### Run Medusa Application (Automated Sync Test) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Medusa development server to test the automated product indexing via the subscriber created for `product.created` and `product.updated` events. ```bash npm run dev ``` -------------------------------- ### Testing Medusa API Route with cURL (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides a cURL command example to test the `/admin/brands` GET API route, showing how to include the authorization token. ```Bash curl 'http://localhost:9000/admin/brands' \ -H 'Authorization: Bearer {token}' ``` -------------------------------- ### Install Medusa Application using create-medusa-app (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command uses npx to execute the latest version of the `create-medusa-app` package, which sets up a new Medusa application project. It prompts the user for project details and optionally installs a starter storefront. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Importing Medusa UI Components in TSX Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Shows a basic example of how to import specific components like `Button` and `Drawer` from the `@medusajs/ui` package into a React/TypeScript file after installation and configuration. ```tsx import { Button, Drawer } from "@medusajs/ui" ``` -------------------------------- ### Create a Loader (TypeScript) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This snippet provides an example of a simple loader function within a Medusa module. Loaders are executed when the Medusa application starts, making them suitable for initialization tasks. ```TypeScript export default async function helloWorldLoader() { console.log( "[HELLO MODULE] Just started the Medusa application!" ) } ``` -------------------------------- ### Testing a Medusa API Route with cURL Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Example command using cURL to send a GET request to the custom `/hello-world` API route running on the local Medusa development server. ```Bash curl http://localhost:9000/hello-world ``` -------------------------------- ### Executing the Workflow via cURL (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides a command-line example using `curl` to send a GET request to the `/workflow` API endpoint. This triggers the execution of the Medusa workflow defined in the application. ```Bash curl http://localhost:9000/workflow ``` -------------------------------- ### Testing the Workflow API Route (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt A `curl` command example to send a GET request to the `/workflow` endpoint, which is configured to execute the `hello-world` workflow. Used to test the API route execution method. ```Bash curl http://localhost:9000/workflow ``` -------------------------------- ### Medusa Subscriber Execution Log (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This is an example log message displayed in the Medusa application's terminal, indicating that the 'order.placed' event was processed and that one subscriber (the one created in this guide) was executed. ```Bash info: Processing order.placed which has 1 subscribers ``` -------------------------------- ### plugin:publish - Medusa CLI Reference Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Publish a plugin into the local packages registry using Yalc. Allows local installation in a Medusa project via `plugin:add`. This command is available starting from Medusa v2.3.0. ```bash npx medusa plugin:publish ``` -------------------------------- ### Using Configured TypeScript Aliases (TypeScript) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides a simple example of importing a module service using the previously configured TypeScript alias (`@/`). This demonstrates the practical application of the alias setup for cleaner and more readable import paths. ```ts import { BrandModuleService } from "@/modules/brand/service" ``` -------------------------------- ### Run Medusa Application (Manual Sync Test) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Medusa development server to test the manual product sync to Algolia via the admin dashboard. ```bash npm run dev ``` -------------------------------- ### Configuring Tailwind Content Path for Medusa UI in Monorepo Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides an example of how to configure the `content` array in `tailwind.config.js` specifically for monorepo setups, using Node.js `path` and `require.resolve` to correctly locate the `@medusajs/ui` package files for Tailwind CSS scanning. ```tsx const path = require("path") const uiPath = path.resolve( require.resolve("@medusajs/ui"), "../..", "\*_/_.{js,jsx,ts,tsx}" ) module.exports = { content: [ // ... uiPath ], // ... } ``` -------------------------------- ### Defining Date Filter Condition for Medusa Admin Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This snippet shows an example of a filter condition object used within a date filter configuration. It defines a condition using the `$lte` operator to filter dates that are less than or equal to the start of the current day. ```TypeScript $lte: new Date(new Date().setHours(0, 0, 0, 0)).toString() }, }, ] }), ] ``` -------------------------------- ### new Command - Medusa CLI Reference Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Create a new Medusa application. Provides flexibility for experienced developers. Includes arguments for directory name and starter URL, and options to skip prompts, database, env, and specify database credentials. ```bash medusa new [ []] ``` -------------------------------- ### Using Query Parameters in Medusa API Route Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Defines a GET API route that accesses query parameters from the request object `req.query`. The example retrieves a parameter named `name` and includes it in the JSON response, illustrating how to handle URL query strings. ```TypeScript import type { MedusaRequest, MedusaResponse, } from "@medusajs/framework/http" export const GET = async ( req: MedusaRequest, res: MedusaResponse ) => { res.json({ message: `Hello ${req.query.name}`, }) } ``` -------------------------------- ### plugin:add - Medusa CLI Reference Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Install specified plugins from the local package registry into a local Medusa application. Plugins must first be published using `plugin:publish`. Requires plugin names as arguments. This command is available starting from Medusa v2.3.0. ```bash npx medusa plugin:add [names...] ``` -------------------------------- ### Create Medusa Application using npx Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Use this command to initialize a new Medusa project. It utilizes npx to run the latest version of create-medusa-app, creating a directory named 'my-medusa-store' (or your chosen name) and setting up the necessary files and a PostgreSQL database. The command will prompt you to optionally install the Next.js storefront. ```bash npx create-medusa-app@latest my-medusa-store ``` -------------------------------- ### Install Medusa Application using create-medusa-app (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This command initializes and installs a new Medusa application project on your local machine using the latest version of the create-medusa-app CLI tool. It sets up the basic project structure and dependencies. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Executing a Workflow in an API Route (TypeScript) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This example demonstrates how to call and run the custom `retrievePriceWithCurrency` workflow from within a Medusa API route handler (a GET request). It shows how to access the scope (which contains the container) from the request object and pass input data to the workflow's `run` method. ```TypeScript import type { MedusaRequest, MedusaResponse, } from "@medusajs/framework/http" import { retrievePriceWithCurrency } from "../../workflows/retrieve-price-with-currency" export async function GET( req: MedusaRequest, res: MedusaResponse ) { const { result } = await retrievePriceWithCurrency(req.scope) .run({ price: 10, }) res.send(result) } ``` -------------------------------- ### Match Text Like Value in MedusaJS List Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt For text-based properties, use the $like operator to perform pattern matching similar to SQL's LIKE clause. Set the property's value to an object containing the $like property with the pattern string. This example finds posts where the title starts with 'My'. ```ts const posts = await postModuleService.listPosts({ title: { $like: "My%", }, }) ``` -------------------------------- ### Apply Date Range Filter ($gte, $lte) in MedusaJS List Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt To filter for records within a specific date range, combine the $gte (greater than or equal to) and $lte (less than or equal to) operators. This is useful for matching records within a single day by setting the start and end times. This example retrieves posts published today. ```ts const startToday = new Date() startToday.setHours(0, 0, 0, 0) const endToday = new Date() endToday.setHours(23, 59, 59, 59) const posts = await postModuleService.listPosts({ published_at: { $gte: startToday, $lte: endToday, }, }) ``` -------------------------------- ### Implementing Search in Medusa DataTable Component (TSX) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This example demonstrates a complete React component using the `@medusajs/ui` DataTable to display and filter product data. It shows the setup of columns, state management for search, data filtering with `useMemo`, configuration of the `useDataTable` hook including search properties, and rendering the search input within the toolbar. ```tsx import { createDataTableColumnHelper, useDataTable, DataTable, Heading } from "@medusajs/ui" import { useMemo, useState } from "react" const products = [ { id: "1", title: "Shirt", price: 10 }, { id: "2", title: "Pants", price: 20 } ] const columnHelper = createDataTableColumnHelper() const columns = [ columnHelper.accessor("title", { header: "Title", enableSorting: true, }), columnHelper.accessor("price", { header: "Price", enableSorting: true, }), ] export default function ProductTable () { const [search, setSearch] = useState("") const shownProducts = useMemo(() => { return products.filter((product) => product.title.toLowerCase().includes(search.toLowerCase())) }, [search]) const table = useDataTable({ columns, data: shownProducts, getRowId: (product) => product.id, rowCount: products.length, isLoading: false, // Pass the state and onSearchChange to the table instance. search: { state: search, onSearchChange: setSearch } }) return ( Products {/* This component renders the search bar */} ) } ``` -------------------------------- ### Manually Installing Sanity Dependencies (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Use this command to manually install required Sanity and related dependencies if the `npx sanity init` command encounters peer dependency errors during installation in the Next.js project. ```Bash yarn add next-sanity@9.8.15 @sanity/client@^6.22.4 @sanity/icons@^3.4.0 @sanity/types@^3.62.0 @sanity/ui@^2.8.10 next@^15.0.0 react@^19.0.0 react-dom@^19.0.0 sanity@^3.62.0 styled-components@^6.1 ``` -------------------------------- ### Setting Up Medusa Database - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Creates a database with the specified name if it doesn't exist, runs migrations, and syncs links. It also updates the .env file with the database name. Requires the --db option. ```bash npx medusa db:setup --db ``` -------------------------------- ### Start Medusa Development Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt To test the new UI route and subsequent API changes, start the Medusa application's development server. This command compiles the project and makes the Admin dashboard accessible locally. ```bash npm run dev ``` -------------------------------- ### Example JSON Response Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt This is an example of the JSON object returned by the API route snippet. ```JSON { "message": "Hello, World!" } ``` -------------------------------- ### Starting Medusa Application (Development) - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Executes the `npm run dev` command to start the Medusa application in development mode. This command typically compiles the project and starts a local server, allowing access to the admin dashboard for testing. ```bash npm run dev ``` -------------------------------- ### Create Medusa Plugin Project (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides the command-line instruction to initialize a new Medusa plugin project using the `create-medusa-app` tool, specifying the project directory name and the `--plugin` flag. ```Bash npx create-medusa-app my-plugin --plugin ``` -------------------------------- ### Example STORE_CORS Environment Variables (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides examples of setting the `STORE_CORS` environment variable in Bash to define allowed origins for Medusa's `/store` routes. Examples include allowing specific local ports, a domain suffix, or all HTTP requests using regular expressions. ```Bash # Allow different ports locally starting with 800 STORE_CORS=/http:\/\/localhost:800\d+$/ # Allow any origin ending with vercel.app. For example, storefront.vercel.app STORE_CORS=/vercel\.app$/ # Allow all HTTP requests STORE_CORS=/http:\/\/.+/ ``` -------------------------------- ### Displaying Medusa CLI Help - Bash Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Shows how to access the help documentation for the Medusa CLI tool using NPX. This command lists available commands and options. ```bash npx medusa --help ``` -------------------------------- ### Example AUTH_CORS Environment Variables (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides examples of setting the `AUTH_CORS` environment variable in Bash to define allowed origins for Medusa's `/auth` routes. Examples include allowing specific local ports, a domain suffix, or all HTTP requests using regular expressions. ```Bash # Allow different ports locally starting with 700 AUTH_CORS=/http:\/\/localhost:700\d+$/ # Allow any origin ending with vercel.app. For example, admin.vercel.app AUTH_CORS=/vercel\.app$/ # Allow all HTTP requests AUTH_CORS=/http:\/\/.+/ ``` -------------------------------- ### General Medusa CLI Usage Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Demonstrates the basic usage of the Medusa CLI tool within your application's directory using NPX to access the help documentation. ```bash npx medusa --help ``` -------------------------------- ### Starting Storefront Development Server (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Executes the `npm run dev` command in the storefront application's root directory. This starts the Next.js storefront development server, typically running on `http://localhost:8000`. ```Bash npm run dev ``` -------------------------------- ### Build Medusa Application Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Shows how to use the `build` command to create a standalone production-ready build of the Medusa application in the `.medusa/server` directory. ```bash npx medusa build ``` -------------------------------- ### Setup File for Medusa Integration Tests (JavaScript) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Create a setup file for Medusa integration tests, typically located at `integration-tests/setup.js`. This specific snippet clears the MikroORM metadata storage, which is often necessary to prevent issues between test runs. ```JavaScript const { MetadataStorage } = require("@mikro-orm/core") MetadataStorage.clear() ``` -------------------------------- ### Starting the Medusa Application (Bash) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Command to start the Medusa application in development mode, typically used after setting up workflows or other customizations to test them. ```Bash npm run dev ``` -------------------------------- ### Installing Monorepository Dependencies (Yarn) Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Installs all necessary dependencies for the Medusa monorepository using Yarn. This command should be run from the root of the cloned repository. ```bash yarn install ``` -------------------------------- ### Installing Medusa UI in Standalone Project via npm Source: https://github.com/mmhobi7/medusajs-docs/blob/master/llms-full.txt Provides the npm command to install the `@medusajs/ui` package for use in any standalone React project. ```bash npm install @medusajs/ui ```