1 import { Prerequisites, Note } from "docs-ui"
2
3 export const metadata = {
4 title: `Clone a Cloud Project Locally`,
5 }
6
7 # {metadata.title}
8
9 In this guide, you'll learn how to clone your Cloud project's repository to your machine and run the Medusa application locally.
10
11 <Prerequisites items={[
12 {
13 text: "Node.js v20.19.0+ or v22.12.0+ installed.",
14 link: "https://nodejs.org/en/download"
15 },
16 {
17 text: "Git installed.",
18 link: "https://git-scm.com/downloads"
19 },
20 {
21 text: "PostgreSQL installed and running locally.",
22 link: "https://www.postgresql.org/download/"
23 }
24 ]} />
25
26 ## Who is this Guide for?
27
28 This guide is for you if you created your project from one of Medusa's [starters](../page.mdx#1-create-project-from-a-starter). In that case, Cloud clones the starter's code into a GitHub repository in the account or organization you chose, and you don't have the code on your machine yet.
29
30 To customize your store, add features, or debug issues, you clone that repository locally and run the application against resources on your machine.
31
32 ---
33
34 ## 1. Clone the Repository
35
36 To clone the repository linked to your project:
37
38 1. [Open the project's dashboard](../page.mdx#open-project-dashboard).
39 2. Click the **Repository** button at the top right to open the GitHub repository in a new tab.
40 3. On GitHub, click the **Code** button and copy the repository's URL.
41 4. In your terminal, clone the repository and change into its directory:
42
43 ```bash
44 git clone <repository-url>
45 cd <repository-name>
46 ```
47
48 Replace `<repository-url>` with the URL you copied, and `<repository-name>` with the name of the created directory.
49
50 ---
51
52 ## 2. Install Dependencies
53
54 Starters are monorepos that hold the Medusa application and the storefront as separate packages, usually under `apps/backend` and `apps/storefront`. Install the dependencies of all packages from the repository's root directory:
55
56 ```bash npm2yarn
57 npm install
58 ```
59
60 Use the same package manager as the starter. To find it, check which lock file the repository has: `package-lock.json` for npm, `yarn.lock` for Yarn, or `pnpm-lock.yaml` for pnpm.
61
62 ---
63
64 ## 3. Set Up Environment Variables
65
66 Starters don't include `.env` files, since they hold secrets that you can't commit to Git. Instead, either copy a `.env.template` or create a `.env` file in the Medusa application's directory that points to resources running on your machine, rather than the resources of a Cloud environment:
67
68 ```bash title="apps/backend/.env"
69 DATABASE_URL=postgres://localhost/medusa-local
70 REDIS_URL=redis://localhost:6379
71 JWT_SECRET=supersecret
72 COOKIE_SECRET=supersecret
73 STORE_CORS=http://localhost:8000
74 ADMIN_CORS=http://localhost:9000
75 AUTH_CORS=http://localhost:9000,http://localhost:8000
76 ```
77
78 Replace the values with the ones matching your setup:
79
80 - `DATABASE_URL`: The connection string of a local PostgreSQL database. Create the database first if it doesn't exist.
81 - `REDIS_URL`: The connection string of a local Redis instance. Remove this variable if you don't run Redis locally, and Medusa falls back to in-memory modules.
82 - `JWT_SECRET` and `COOKIE_SECRET`: Any random strings. Use different values than the ones in your Cloud environments.
83 - `STORE_CORS`, `ADMIN_CORS`, and `AUTH_CORS`: The local URLs that can send requests to the Medusa application. Change `http://localhost:8000` if your storefront runs on another port.
84
85 Local resources keep your development work isolated, so you can seed and change data without affecting a deployed store. Learn about the rest of the available configurations in the [Medusa Configurations](!docs!/learn/configurations/medusa-config) guide.
86
87 For the storefront, create a `.env` file in its directory with the variables it expects. Refer to the starter's `.env.template` file for the list of variables.
88
89 <Note title="Tip" forceMultiline>
90
91 If you need your local setup to mirror a deployed environment, you can reuse that environment's variables instead. Either [export the variables](../../environments/environment-variables/page.mdx#export-environment-variables-on-cloud) from the environment's dashboard and rename the downloaded `env.txt` file to `.env`, or run the following command with the [Cloud CLI](../../cli/page.mdx):
92
93 ```bash
94 mcloud variables list --reveal --dotenv > .env
95 ```
96
97 Pass `--type storefront` to export the storefront's variables instead. Learn more in the [variables command reference](../../cli/commands/variables/page.mdx#export-variables-to-a-env-file).
98
99 Since these variables point to the environment's database, Redis instance, and other resources, any change you make locally affects the deployed environment. Only reuse them for debugging, and prefer local resources for development.
100
101 </Note>
102
103 ---
104
105 ## 4. Run the Application Locally
106
107 Change to the Medusa application's directory, then run the migrations to prepare your local database:
108
109 ```bash
110 npx medusa db:migrate
111 ```
112
113 Next, create an admin user to log into the Medusa Admin locally:
114
115 ```bash
116 npx medusa user -e admin@medusajs.com -p supersecret
117 ```
118
119 Then, start the Medusa application:
120
121 ```bash npm2yarn
122 npm run dev
123 ```
124
125 The Medusa application runs at `http://localhost:9000`, and the Medusa Admin at `http://localhost:9000/app`. Learn more in the [Installation](!docs!/learn/installation) guide.
126
127 To run the storefront, refer to the starter's README file in the repository. It has the commands and variables specific to the storefront.
128
129 ---
130
131 ## Push Local Changes to Cloud
132
133 Cloud deploys your changes when you push them to the GitHub repository linked to your project. Push to the branch of a [long-lived environment](../../environments/long-lived/page.mdx) to deploy to that environment, or open a pull request to create a [preview environment](../../environments/preview/page.mdx).