### Set Start Command for Production Source: https://docs.medusajs.com/learn/deployment/general/index.html Command to install dependencies and start the Medusa server when the working directory cannot be set directly. ```bash cd .medusa/server && npm install && npm run predeploy && npm run start ``` -------------------------------- ### Start Storefront for Testing Source: https://docs.medusajs.com/llms-full.txt Commands to navigate to the storefront directory and start the development server. ```bash cd apps/storefront ``` ```bash npm run dev ``` -------------------------------- ### Start Development Servers Source: https://docs.medusajs.com/llms-full.txt Commands to start the Medusa application and the Next.js storefront. ```bash npm run dev ``` ```bash npm run dev ``` -------------------------------- ### Install react-markdown Source: https://docs.medusajs.com/llms-full.txt Install the dependency required to render markdown product descriptions. ```bash npm install react-markdown ``` -------------------------------- ### Start Development Servers Source: https://docs.medusajs.com/llms-full.txt Commands to start the Strapi and Medusa development servers for testing. ```bash npm run develop ``` ```bash npm run dev ``` -------------------------------- ### Install Resend SDK Source: https://docs.medusajs.com/llms-full.txt Installs the official Resend SDK package. ```bash npm install resend ``` -------------------------------- ### Install Loyalty Plugin Source: https://docs.medusajs.com/llms-full.txt Install the required package via npm. ```bash npm install @medusajs/loyalty-plugin ``` -------------------------------- ### Install Moment.js Library Source: https://docs.medusajs.com/llms-full.txt Install the Moment.js library to facilitate date manipulation and formatting. ```bash npm install moment ``` -------------------------------- ### Install Contentful SDKs Source: https://docs.medusajs.com/llms-full.txt Install the necessary Contentful management and delivery SDKs in the backend directory. ```bash npm install contentful contentful-management ``` -------------------------------- ### Install AvaTax SDK Source: https://docs.medusajs.com/llms-full.txt Install the required Avalara SDK package in the backend directory. ```bash npm install avatax ``` -------------------------------- ### Install Dependencies for Production Build Source: https://docs.medusajs.com/llms-full.txt Navigates to the build directory and installs necessary production dependencies. ```bash cd .medusa/server && npm install ``` -------------------------------- ### Install Algolia Dependencies Source: https://docs.medusajs.com/llms-full.txt Install the Algolia search client and React InstantSearch library. ```bash npm install algoliasearch react-instantsearch ``` -------------------------------- ### Install PayPal React SDK Source: https://docs.medusajs.com/llms-full.txt Install the PayPal React SDK dependency in the storefront project. ```bash npm install @paypal/react-paypal-js ``` -------------------------------- ### Setup Database Source: https://docs.medusajs.com/resources/medusa-cli/commands/db Creates the database and executes all migrations. ```bash yarn medusa db:setup ``` ```bash pnpm medusa db:setup ``` ```bash npx medusa db:setup ``` -------------------------------- ### Install Sanity Dependencies Source: https://docs.medusajs.com/llms-full.txt Use this command to manually install peer dependencies if the initial setup fails. ```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 ``` -------------------------------- ### Set Start Command for Worker Deployment Source: https://docs.medusajs.com/llms-full.txt Command to install dependencies and start the Medusa server from the build output directory. ```bash cd .medusa/server && npm install && npm run start ``` -------------------------------- ### Setup the database Source: https://docs.medusajs.com/llms-full.txt Creates a database, runs migrations, and syncs links. Updates the .env file with the database name. ```bash npx medusa db:setup --db ``` -------------------------------- ### Setup Database Source: https://docs.medusajs.com/resources/medusa-cli/commands/db Initializes the database using the specified database name. ```bash npx medusa db:setup --db ``` -------------------------------- ### Set Start Command for Worker Mode Source: https://docs.medusajs.com/learn/deployment/general/index.html Command to install dependencies and start the Medusa server from the build directory. Use this if your hosting provider does not support setting a custom working directory. ```bash cd .medusa/server && npm install && npm run start ``` ```yarn cd .medusa/server && yarn install && yarn run start ``` ```pnpm cd .medusa/server && pnpm install && pnpm run start ``` -------------------------------- ### Start the development server Source: https://docs.medusajs.com/llms-full.txt Commands to navigate to the project directory and launch the development environment. ```bash cd my-medusa-store npm run dev ``` -------------------------------- ### GET /admin/products Source: https://docs.medusajs.com/api/admin Example of using the fields query parameter to filter the returned product fields. ```APIDOC ## GET /admin/products ### Description Retrieves a list of products with specific fields selected using the fields query parameter. ### Method GET ### Endpoint /admin/products ### Query Parameters - **fields** (string) - Optional - A comma-separated list of fields to include or exclude. Use '+' to add a field to the default set or '-' to remove a field. ### Request Example curl 'localhost:9000/admin/products?fields=title,handle' \ -H 'Authorization: Bearer {jwt_token}' ``` -------------------------------- ### GET /admin/products (Pagination) Source: https://docs.medusajs.com/api/admin Example of using pagination query parameters to limit and offset results when listing resources. ```APIDOC ## GET /admin/products ### Description Retrieves a list of products with pagination support. ### Method GET ### Endpoint /admin/products ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of items to return. - **offset** (integer) - Optional - The number of items to skip. ### Request Example curl "http://localhost:9000/admin/products?limit=5&offset=0" \ -H 'Authorization: Bearer {jwt_token}' ### Response #### Success Response (200) - **limit** (integer) - The maximum number of items that can be returned in the response. - **offset** (integer) - The number of items that were skipped before the records in the result. ``` -------------------------------- ### Create a new Medusa store Source: https://docs.medusajs.com/llms-full.txt Example command to initialize a project named my-medusa-store. ```bash medusa new my-medusa-store ``` -------------------------------- ### Run db:setup command Source: https://docs.medusajs.com/resources/medusa-cli/commands/db Creates a database with the specified name, runs migrations, and syncs links. It also updates the .env file with the new database name. ```bash yarn medusa db:setup --db ``` ```bash pnpm medusa db:setup --db ``` ```bash npx medusa db:setup --db ``` -------------------------------- ### Configure Claude Code for Learning Medusa Source: https://docs.medusajs.com/learn/installation/index.html Installs the learn-medusa skill for Claude Code to start an interactive learning experience. ```bash claude # start claude code /plugin marketplace add medusajs/medusa-agent-skills /plugin install learn-medusa@medusa # then use the following prompt to start learning: I want to learn Medusa. ``` -------------------------------- ### Implement DataTable with Initial Filters Source: https://docs.medusajs.com/llms-full.txt A complete example showing the setup of columns, filters, and the initial filtering state for a DataTable. ```tsx import { DataTable, DataTableFilteringState, Heading, createDataTableColumnHelper, createDataTableFilterHelper, useDataTable } 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, }), ] const filterHelper = createDataTableFilterHelper() const filters = [ filterHelper.accessor("title", { type: "select", label: "Title", options: products.map((product) => ({ label: product.title, value: product.title.toLowerCase() })) }), ] export default function ProductTable () { const [filtering, setFiltering] = useState({ title: ["shirt"] }) const shownProducts = useMemo(() => { return products.filter((product) => { return Object.entries(filtering).every(([key, value]) => { if (!value) { return true } if (typeof value === "string") { // @ts-ignore return product[key].toString().toLowerCase().includes(value.toString().toLowerCase()) } if (Array.isArray(value)) { // @ts-ignore return value.includes(product[key].toLowerCase()) } if (typeof value === "object") { // @ts-ignore const date = new Date(product[key]) let matching = false if ("$gte" in value && value.$gte) { matching = date >= new Date(value.$gte as number) } if ("$lte" in value && value.$lte) { matching = date <= new Date(value.$lte as number) } if ("$lt" in value && value.$lt) { matching = date < new Date(value.$lt as number) } if ("$gt" in value && value.$gt) { matching = date > new Date(value.$gt as number) } return matching } }) }) }, [filtering]) const table = useDataTable({ data: shownProducts, columns, getRowId: (product) => product.id, rowCount: products.length, isLoading: false, filtering: { state: filtering, onFilteringChange: setFiltering, }, filters }); return ( Products {/** This component will render a menu that allows the user to choose which filters to apply to the table data. **/} ); }; ``` -------------------------------- ### Setup Database Source: https://docs.medusajs.com/resources/medusa-cli/commands/db Recreate and reinitialize the database using the Medusa CLI. ```bash yarn medusa db:setup --db ``` ```bash pnpm medusa db:setup --db ``` -------------------------------- ### Running migrations and starting the application Source: https://docs.medusajs.com/learn/fundamentals/module-links/index-module/index.html Execute database migrations and start the development server to sync links and ingest data models. ```bash npx medusa db:migrate ``` ```bash npm run dev ``` -------------------------------- ### Implement Full DataTable Pagination Source: https://docs.medusajs.com/llms-full.txt A complete example showing the setup of state, columns, and the DataTable component with pagination controls. ```tsx import { DataTable, Heading, createDataTableColumnHelper, useDataTable, type DataTablePaginationState } from "@medusajs/ui" import { useMemo, useState } from "react" const products = [ { id: "1", title: "Shirt", price: 10 }, { id: "2", title: "Pants", price: 20 }, { id: "3", title: "Hat", price: 15 }, { id: "4", title: "Socks", price: 5 }, { id: "5", title: "Shoes", price: 50 }, { id: "6", title: "Jacket", price: 100 }, { id: "7", title: "Scarf", price: 25 }, { id: "8", title: "Gloves", price: 12 }, { id: "9", title: "Belt", price: 18 }, { id: "10", title: "Sunglasses", price: 30 }, { id: "11", title: "Watch", price: 200 }, { id: "12", title: "Tie", price: 20 }, { id: "13", title: "Sweater", price: 40 }, { id: "14", title: "Jeans", price: 60 }, { id: "15", title: "Shorts", price: 25 }, { id: "16", title: "Blouse", price: 35 }, { id: "17", title: "Dress", price: 80 } ] const columnHelper = createDataTableColumnHelper() const columns = [ columnHelper.accessor("title", { header: "Title", enableSorting: true, }), columnHelper.accessor("price", { header: "Price", enableSorting: true, }), ] const PAGE_SIZE = 10; export default function ProductTable () { const [pagination, setPagination] = useState({ pageSize: PAGE_SIZE, pageIndex: 0, }) const shownProducts = useMemo(() => { return products.slice( pagination.pageIndex * pagination.pageSize, (pagination.pageIndex + 1) * pagination.pageSize ) }, [pagination]) const table = useDataTable({ data: shownProducts, columns, rowCount: products.length, getRowId: (product) => product.id, pagination: { // Pass the pagination state and updater to the table instance state: pagination, onPaginationChange: setPagination, }, isLoading: false, }); return ( Products {/** This component will render the pagination controls **/} ); }; ``` -------------------------------- ### Initialize environment files Source: https://docs.medusajs.com/llms-full.txt Copies template files to create active environment configurations for backend and storefront services. ```bash cp apps/backend/.env.template apps/backend/.env ``` ```bash cp apps/storefront/.env.template apps/storefront/.env ``` -------------------------------- ### Full DataTable Bulk Action Implementation Source: https://docs.medusajs.com/llms-full.txt A complete example demonstrating the setup of columns, commands, and the DataTable component with selection state. ```tsx import { DataTable, DataTableRowSelectionState, Heading, createDataTableColumnHelper, createDataTableCommandHelper, useDataTable } from "@medusajs/ui" import { useState } from "react" let products = [ { id: "1", title: "Shirt", price: 10, }, { id: "2", title: "Pants", price: 20, } ] const columnHelper = createDataTableColumnHelper() const columns = [ // Commands requires a select column. columnHelper.select(), columnHelper.accessor("title", { header: "Title", enableSorting: true, }), columnHelper.accessor("price", { header: "Price", enableSorting: true, }), ] const commandHelper = createDataTableCommandHelper() const useCommands = () => { return [ commandHelper.command({ label: "Delete", shortcut: "D", action: async (selection) => { const productsToDeleteIds = Object.keys(selection) alert(`You deleted product(s) with IDs: ${productsToDeleteIds.join()}`) } }) ] } export default function ProductTable () { const [rowSelection, setRowSelection] = useState({}) const commands = useCommands() const instance = useDataTable({ data: products, columns, getRowId: (product) => product.id, rowCount: products.length, isLoading: false, commands, rowSelection: { state: rowSelection, onRowSelectionChange: setRowSelection, }, }); return ( Products {/** This component will the command bar when the user has selected at least one row. **/} `${count} selected`} /> ); }; ``` -------------------------------- ### Initialize Strapi Project Source: https://docs.medusajs.com/llms-full.txt Creates a new Strapi project and navigates into the directory. ```bash npx create-strapi@latest my-strapi-app ``` ```bash cd my-strapi-app ``` -------------------------------- ### MFA Factor Enrollment Response Source: https://docs.medusajs.com/llms-full.txt Example JSON response containing the pending MFA factor details and the TOTP setup URL. ```json { "mfa_factor": { "id": "authmfa_...", "status": "pending", ... }, "secret": "JBSWY3DPEHPK3PXP", "otpauth_url": "otpauth://totp/My%20Store:user@example.com?secret=..." } ``` -------------------------------- ### Example Prompts for Medusa Development Source: https://docs.medusajs.com/learn/introduction/build-with-llms-ai/agentic-skills/index.html Sample prompts to guide AI agents in building features, API routes, and dashboard customizations. ```text Implement a product reviews feature. Authenticated customers can add reviews. Admin users can view and approve or reject reviews from the dashboard Create a wishlist feature where customers can save products. I need API routes for adding/removing items and retrieving the wishlist. Add a widget to the product detail page in the admin that allows managing related products. Admin users should be able to select which products are related using a searchable table. Help me integrate the custom reviews API into my Next.js storefront. Show product reviews on the product detail page with pagination. ``` -------------------------------- ### Implement Streaming in a Next.js Route Source: https://docs.medusajs.com/resources/js-sdk This example demonstrates how to use fetchStream to handle streaming data in a React component, including starting the stream and aborting it. ```tsx
{messages.length === 0 ? ( No messages yet... ) : ( messages.map((msg, index) => (
{msg}
)) )}
) } export const config = defineRouteConfig({ label: "Stream Test", }) export default StreamTestPage ``` -------------------------------- ### Clone the DTC Starter Repository Source: https://docs.medusajs.com/llms-full.txt Initializes the project by cloning the repository and navigating into the directory. ```bash git clone https://github.com/medusajs/dtc-starter.git --depth=1 my-medusa-store cd my-medusa-store ``` -------------------------------- ### Using Tanstack Query in Admin Widgets Source: https://docs.medusajs.com/learn/fundamentals/admin/tips Examples demonstrating how to perform GET requests with useQuery and POST/DELETE requests with useMutation in Medusa admin widgets. ```tsx import { defineWidgetConfig } from "@medusajs/admin-sdk" import { Container } from "@medusajs/ui" import { useQuery } from "@tanstack/react-query" import { sdk } from "../lib/sdk" const ProductWidget = () => { const { data, isLoading } = useQuery({ queryFn: () => sdk.admin.product.list(), queryKey: ["products"], }) return ( {isLoading && Loading...} {data?.products && (
    {data.products.map((product) => (
  • {product.title}
  • ))}
)}
) } export const config = defineWidgetConfig({ zone: "product.list.before", }) export default ProductWidget ``` ```tsx import { defineWidgetConfig } from "@medusajs/admin-sdk" import { Button, Container } from "@medusajs/ui" import { useMutation } from "@tanstack/react-query" import { sdk } from "../lib/sdk" import { DetailWidgetProps, HttpTypes } from "@medusajs/framework/types" const ProductWidget = ({ data: productData, }: DetailWidgetProps) => { const { mutateAsync } = useMutation({ mutationFn: (payload: HttpTypes.AdminUpdateProduct) => sdk.admin.product.update(productData.id, payload), onSuccess: () => alert("Product updated"), }) const handleUpdate = () => { mutateAsync({ title: "New Product Title", }) } return ( ``` -------------------------------- ### Navigate to Storefront Directory Source: https://docs.medusajs.com/llms-full.txt Use this command to switch to the storefront directory from the parent project folder. ```bash cd ../medusa-ticketing-storefront # change based on your project name ``` -------------------------------- ### Full DataTable Search Implementation Source: https://docs.medusajs.com/llms-full.txt A complete example showing the setup of columns, state management for search, data filtering, and the DataTable component structure. ```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 */} ) } ``` -------------------------------- ### Initialize Medusa v2 Database Source: https://docs.medusajs.com/llms-full.txt Run the database setup command to create the necessary tables for the v2 project. ```bash npx medusa db:setup ``` -------------------------------- ### Implementing a GET API Route with Query Configuration Source: https://docs.medusajs.com/learn/fundamentals/module-links/query This example demonstrates how to resolve the query service and pass req.queryConfig to the query.graph method within a custom API route. ```ts import { MedusaRequest, MedusaResponse, } from "@medusajs/framework/http" import { ContainerRegistrationKeys, } from "@medusajs/framework/utils" export const GET = async ( req: MedusaRequest, res: MedusaResponse ) => { const query = req.scope.resolve(ContainerRegistrationKeys.QUERY) const { data: posts } = await query.graph({ entity: "post", ...req.queryConfig, }) res.json({ posts: posts }) } ``` -------------------------------- ### Install Medusa Application Source: https://docs.medusajs.com/llms-full.txt Initializes a new Medusa project as a monorepository. ```bash npx create-medusa-app@latest ``` -------------------------------- ### Install dependencies with pnpm Source: https://docs.medusajs.com/llms-full.txt Run the installation command to generate the pnpm-lock.yaml file and install project dependencies. ```bash pnpm install ``` -------------------------------- ### Create start-storefront.sh for Next.js Storefront Source: https://docs.medusajs.com/llms-full.txt Shell script to start the Next.js storefront development server. ```shell #!/bin/sh cd /server/apps/storefront echo "Starting Next.js Starter Storefront development server..." pnpm dev ``` ```shell #!/bin/sh cd /server/apps/storefront echo "Starting Next.js Starter Storefront development server..." yarn dev ``` ```shell #!/bin/sh cd /server/apps/storefront echo "Starting Next.js Starter Storefront development server..." npm run dev ``` -------------------------------- ### Install Dependencies Source: https://docs.medusajs.com/learn/update Install the latest versions of Medusa packages. ```bash yarn install ``` ```bash pnpm install ``` ```bash npm install ``` -------------------------------- ### Install @medusajs/test-utils Source: https://docs.medusajs.com/learn/debugging-and-testing/testing-tools/index.html Install the testing framework as a development dependency. ```bash npm install --save-dev @medusajs/test-utils@latest ``` -------------------------------- ### Start the Medusa application Source: https://docs.medusajs.com/learn/build/index.html Launch the application from the server directory. ```bash npm run start ``` ```yarn yarn start ``` -------------------------------- ### Install Medusa Ecommerce Store Source: https://docs.medusajs.com/llms-full.txt Use this command to initialize a new Medusa project including the Node.js server, Admin dashboard, and Next.js storefront. ```bash npx create-medusa-app@latest --with-nextjs-starter ``` -------------------------------- ### Install Phone Input Package Source: https://docs.medusajs.com/llms-full.txt Install the react-phone-number-input dependency for the storefront. ```bash npm install react-phone-number-input ``` -------------------------------- ### Install dependencies in the build directory Source: https://docs.medusajs.com/learn/build/index.html Navigate to the generated server directory and install required dependencies. ```bash cd .medusa/server && npm install ``` ```yarn cd .medusa/server && yarn install ``` -------------------------------- ### Install Dependencies Source: https://docs.medusajs.com/learn/resources/contribution-guidelines/admin-translations/index.html Install all necessary dependencies for the monorepository using Yarn. ```bash yarn install ``` -------------------------------- ### Install Strapi Client Source: https://docs.medusajs.com/llms-full.txt Run this command in the apps/backend directory to install the necessary Strapi client dependency. ```bash npm install @strapi/client ``` -------------------------------- ### Example Prompts for Storefront Development Source: https://docs.medusajs.com/learn/introduction/build-with-llms-ai/agentic-skills/index.html Sample prompts for building or modifying ecommerce storefronts using AI agents. ```text Build a Next.js ecommerce storefront that uses Medusa as the backend. The storefront should have product listing, product detail, cart, and checkout pages. Add a megamenu to the storefront's header that displays product categories and subcategories. The menu should be responsive and work well on mobile devices. ``` -------------------------------- ### Install Jest Dependencies Source: https://docs.medusajs.com/learn/debugging-and-testing/testing-tools/index.html Install the required Jest packages for testing. ```bash npm install --save-dev jest @types/jest @swc/jest ``` -------------------------------- ### Initialize Medusa with an AI Agent Source: https://docs.medusajs.com/learn/index.html Use this prompt with an AI agent to automatically set up a Medusa project and deploy it to Medusa Cloud. ```bash Fetch https://docs.medusajs.com/start and create an ecommerce store with Medusa Cloud ``` -------------------------------- ### Install Meilisearch Dependencies Source: https://docs.medusajs.com/llms-full.txt Install the required Meilisearch and React InstantSearch packages. ```bash npm install @meilisearch/instant-meilisearch react-instantsearch ``` -------------------------------- ### Install stream-json Source: https://docs.medusajs.com/llms-full.txt Command to install the necessary dependencies for streaming JSON parsing. ```bash npm install stream-json @types/stream-json ```