How to Connect Medusa.js to Supabase

Integrating Medusa.js with Supabase can enhance your e-commerce capabilities by leveraging Medusa’s flexibility and Supabase’s powerful database management.

Medusa.jsE-Commerce
SupabaseDatabase

Tom McCulloch

Read Time: 2 min

Download pgAdmin

To manage your PostgreSQL databases, you will need pgAdmin. You can download it from the pgAdmin download page.

Get Credentials from Supabase

Retrieve your database credentials from Supabase:

Go to your Supabase Dashboard, Project Settings, Database

Note down the necessary credentials such as the host, database name, username, and password under the connection parametres.

Add PostgreSQL’s Bin to Your System’s PATH Environment Variable

To use PostgreSQL’s command-line tools, add its bin directory to your system’s PATH:

Locate PostgreSQL Bin Directory:

Typically, it’s found at C:\Program Files\PostgreSQL\<version>\bin.

Add to PATH:

Right-click on the Start button and select “System”.

In the search bar, type “View Advanced System Settings” and open it.

In the window that opens, ensure the “Advanced” tab is selected and click “Environment Variables” at the bottom.

In “User variables for {user}”, select “Path” and click “Edit”.

In the “Edit Environment Variables” window, click “New” and paste the path to your PostgreSQL’s bin directory:

C:\Program Files\PostgreSQL\<version>\bin

Save and close all the windows.

Verify Installation

Close and reopen a new terminal in VSCode.

Run the following command to check if psql is working:

psql --version

You should see the version information in the terminal.

Connect to Supabase:

Use the following command to connect to your Supabase database, replacing the placeholders with your actual credentials:

psql -h aws-0-ap-southeast-2.pooler.supabase.com -U postgres.{USER} -d postgres -p 6543

When prompted, insert the password.

Set Up Medusa.js with Supabase

Navigate to Your Desired Project Directory:

Open a terminal and navigate to the directory where you want to create your Medusa project.

Create Medusa Project:

Run the following command in the terminal, replacing {PASSWORD} with your actual Supabase password:

npx create-medusa-app@latest --with-nextjs-starter --db-url "postgres://postgres.{YOUR_DATABASE_USER}:{PASSWORD}@aws-0-ap-southeast-2.pooler.supabase.com:6543/postgres"

Following these steps will set up a Medusa.js project connected to a Supabase database, allowing you to leverage the benefits of both platforms for your e-commerce site.