sethserver.com Subscribe
Robot inserting fork into electrical outlet

How to Connect Replit to Supabase Postgres Database (Node.js & Python Guide)

By Seth Black • Updated: September 17, 2026

Programming · 7 min read

Like this kind of writing? Get one email a week with notes on startups, AI, and the occasional strong opinion about Python: subscribe to the newsletter.

You can spend a whole afternoon thinking Supabase is some exotic new database thing.

It's not. It's Postgres.

Supabase is PostgreSQL with some nice stuff bolted on: auth, storage, and auto-generated APIs. That's useful. But the database part is still the same old, dependable Postgres you'd connect to anywhere else.

Connecting Replit to Supabase mostly comes down to grabbing the right connection details, putting them in Secrets, and keeping them out of git. Full stop.

What you need from Supabase

Go to your Supabase project and find the database connection info. Supabase documents it here:
https://supabase.com/docs/guides/database/connecting-to-postgres

You're looking for the same fields you'd need for any Postgres server:

Where to find it (and what to copy)

In the Supabase dashboard, you'll usually find this under Project Settings - Database - Connection string (the exact menu names change sometimes, but it's always "Settings" and "Database" somewhere).

Supabase often shows multiple connection strings. Common ones:

If you're building a small app on Replit, start with the standard direct connection string unless Supabase tells you otherwise.

A DATABASE_URL looks like this:

postgresql://USER:PASSWORD@HOST:5432/DATABASE

Sometimes it includes extra parameters like ?sslmode=require. That's fine.

If you don't use a connection string, you can still connect with the individual parts. But the connection string is harder to mess up and easier to drop into libraries.

Quick sanity check

Before you even touch Replit, check that your credentials make sense:

If you've ever connected to RDS, Neon, or a random Postgres box under someone's desk, this is the same checklist.

Put credentials in Replit Secrets (not your code)

In Replit, click the lock icon (Secrets). This is where environment variables live. Your code reads them, but they don't get committed to git.

Add either:

Option A (recommended): one variable

This keeps your app config clean. Most libraries support it directly, and it's the least typing.

Option B: individual variables

This can be nice if you want to change hosts or users without editing a huge string, but it's more pieces to manage.

Either way, don't commit credentials to git. Not "try not to." Don't.

I've watched teams do a full incident response because someone pushed a .env file. It's never a fun day. It's also never necessary. If you do slip up, rotate the password immediately. Don't debate it. Rotate it.

One more practical note: Replit deployments and secrets

If you're using Replit Deployments (or any hosted deployment flow), double-check that the deployment environment has the same secrets. Local repl secrets and deployment secrets can be separate depending on your setup. The fastest way to confirm is to log process.env.DATABASE_URL ? "set" : "missing" (not the actual value).

Node.js example (pg)

Install:

npm i pg

Use a pool:

import pg from "pg";
const { Pool } = pg;

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  ssl: { rejectUnauthorized: true },
});

const result = await pool.query("select now() as server_time;");
console.log(result.rows[0]);

That query is boring on purpose. If it runs, your app can talk to the database.

A slightly more realistic Node example

Here's a tiny pattern I use a lot: create a table if it doesn't exist, insert a row, then read it back.

import pg from "pg";
const { Pool } = pg;

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  ssl: { rejectUnauthorized: true },
});

await pool.query(`
  create table if not exists notes (
    id bigserial primary key,
    body text not null,
    created_at timestamptz not null default now()
  );
`);

const inserted = await pool.query(
  "insert into notes (body) values ($1) returning id, created_at;",
  ["hello from replit"],
);

const rows = await pool.query(
  "select id, body, created_at from notes order by id desc limit 5;",
);

console.log({ inserted: inserted.rows[0], recent: rows.rows });

A few details worth calling out:

Common Node gotchas

Python example (psycopg)

Install:

pip install psycopg[binary]

Supabase uses SSL. Use it. Plaintext database traffic is a great way to leak user data.

You'll also want the server root certificate from the Supabase dashboard. Save it as something like supabase-ca.crt.

import os
import psycopg
from psycopg.context import make_ssl_context
from psycopg.pq import SSLMode

sslctx = make_ssl_context(
    sslmode=SSLMode.VERIFY_CA,
    cafile="supabase-ca.crt",
)

with psycopg.connect(os.environ["DATABASE_URL"], ssl_context=sslctx) as conn:
    with conn.cursor() as cur:
        cur.execute("select version();")
        print(cur.fetchone()[0])

A more practical Python example (with parameters)

import os
import psycopg
from psycopg.context import make_ssl_context
from psycopg.pq import SSLMode

sslctx = make_ssl_context(
    sslmode=SSLMode.VERIFY_CA,
    cafile="supabase-ca.crt",
)

with psycopg.connect(os.environ["DATABASE_URL"], ssl_context=sslctx) as conn:
    with conn.cursor() as cur:
        cur.execute("""
            create table if not exists events (
              id bigserial primary key,
              name text not null,
              created_at timestamptz not null default now()
            );
        """)
        cur.execute(
            "insert into events (name) values (%s) returning id;",
            ("replit_connected",),
        )
        event_id = cur.fetchone()[0]

        cur.execute(
            "select id, name, created_at from events where id = %s;",
            (event_id,),
        )
        print(cur.fetchone())

Notes:

Common Python gotchas

SSL security

Always connect using SSL to prevent snooping and man-in-the-middle attacks. Your database traffic can include:

Supabase provides the server root certificate in the dashboard. Download it, store it in your project, and point your client at it.

SSL settings, in plain English

If you can use verify-full cleanly, great. If it's a hassle due to hostname mismatch or tooling quirks, verify-ca is still a big step up from "turn SSL off and hope."

If you get SSL errors, don't start randomly turning SSL off. Fix the cert path. Fix the mode. Keep the lock on the door.

A quick opinion on databases (since people will ask)

Postgres is great for:

It's also great for boring stuff like "store users and their posts," which is most apps.

MySQL can be faster for simple CRUD in some setups, especially when your queries are straightforward and you've tuned it well. MongoDB can be fine if your data shape changes constantly and you don't want to fight a schema early on.

Practical tradeoffs I see in early-stage apps

I've watched startups burn months migrating databases because someone read a blog post about "scale." Meanwhile, they had 12 users and half of them were employees.

Pick Postgres. Ship the product. Optimize after you have real traffic and real pain.

Related links

-Sethers

Share this post
Newsletter

One email, once a week.

Notes on databases, systems, and the occasional strong opinion about Python. No spam, unsubscribe anytime.

Seth Black
Written by

Seth Black

Engineer and founder based in Texas. Writes about databases, AI, and running things in production. Embeds in small teams as lead engineer.

More from Programming

View all →
Programming

What's the Differences Between Relational, NoSQL, Vectors, and Caches

Apr 14, 2026
Programming

Git and Source Control in AI Land

Apr 14, 2026
Programming

Domains, DNS, and why it feels fragile

Apr 14, 2026