---
title: "How to Connect Replit to Supabase Postgres Database (Node.js & Python Guide)"
description: "Learn how to connect your Replit app to Supabase PostgreSQL securely. Step-by-step guide covering connection strings, environment secrets, SSL configuration, and working code examples in Node.js and Python for building database-backed apps."
image: "https://cdn.sethserver.com/blog-images/connecting-replit-to-supabase-postgres-social.webp"
---

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

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:

- **Host**
- **Database name**
- **Port** (usually `5432`)
- **User**
- **Password**
- Optional but easiest: a **connection string** / **URI** (often called `DATABASE_URL`)

### 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:

- **Direct connection** (typical for servers)
- **Connection pooling** (good for lots of short-lived connections)
- Sometimes a "Session" mode vs "Transaction" mode if they're using PgBouncer

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:

- Host looks like a real hostname (not `localhost`)
- Port is `5432` unless you changed it
- Database name is not blank
- User is something like `postgres` or a project-specific role
- Password is not the one you used on a random demo app in 2021

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

- `DATABASE_URL` = your full Postgres connection string

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

### Option B: individual variables

- `PGHOST`
- `PGUSER`
- `PGPASSWORD`
- `PGDATABASE`
- `PGPORT`

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:

```bash
npm i pg
```

Use a pool:

```js
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.

```js
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:

- Use `$1`, `$2`, etc. for parameters. Don't string-concatenate SQL.
- Use a `Pool`, not a new client per request. Creating connections repeatedly is slow and can hit connection limits.
- If you're building an API server, keep the pool at module scope so it's reused.

### Common Node gotchas

- **`DATABASE_URL` missing**: your code works locally, but the repl doesn't have the secret set. Fix secrets first, not code.
- **Too many connections**: if you create a new `Pool` inside every request handler, you'll melt your database. Create it once.
- **SSL errors**: don't "fix" it by disabling SSL. Fix the cert settings (more on that below).

## Python example (psycopg)

Install:

```bash
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`.

```python
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)

```python
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:

- Psycopg uses `%s` placeholders for parameters.
- The `with` block commits automatically on success and rolls back on exceptions. That's a nice default for small scripts.
- If you're building a web app, you'll usually want a connection pool (psycopg has pooling options), but start simple.

### Common Python gotchas

- **Wrong cert path**: in Replit, your working directory matters. Make sure `supabase-ca.crt` is actually where your code expects it.
- **Using old psycopg2 snippets**: psycopg (v3) and psycopg2 differ. The code above is for psycopg v3.
- **Disabling SSL to "make it work"**: it may connect, but you're choosing the unsafe path. Fix SSL.

## SSL security

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

- user emails
- password hashes (hopefully hashes)
- API keys
- private messages
- whatever else you promised users you wouldn't leak

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

- `sslmode=require`: encrypts traffic, but may not verify the server identity.
- `VERIFY_CA` / `verify-ca`: verifies the certificate chain against the CA file you provide.
- `VERIFY_FULL` / `verify-full`: verifies CA and hostname. This is the strictest.

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:

- complex queries
- joins that don't make you cry
- vectors (pgvector is real and useful)
- geospatial (PostGIS works)
- anything involving real math

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

- If you need relational integrity (users - teams - roles - permissions), Postgres saves you from weird bugs.
- If you're doing analytics queries ("group by day, filter by plan, join with referrals"), Postgres is comfortable.
- If you're storing documents that change shape every week, MongoDB can reduce friction, but you pay for it later in query complexity and data consistency.
- If you're building an LLM app, Postgres + pgvector is often enough for a first version. You can add a dedicated vector database later if you hit real limits.

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

- [What is a startup](https://example.com/what-is-a-startup)
- [Connecting your Replit app to AWS RDS PostgreSQL](https://example.com/replit-to-rds-postgres)
- [Connecting your Replit app to AWS RDS MySQL](https://example.com/replit-to-rds-mysql)

-Sethers


```json
{"@context": "https://schema.org", "@type": "BlogPosting", "headline": "How to Connect Replit to Supabase Postgres Database (Node.js & Python Guide)", "datePublished": "2026-01-14T05:23:01", "dateModified": "2026-09-17T19:47:57", "image": {"@type": "ImageObject", "url": "https://cdn.sethserver.com/blog-images/connecting-replit-to-supabase-postgres-social.webp", "width": 400, "height": 400}, "url": "https://www.sethserver.com/programming/connecting-replit-to-supabase-postgres.html", "author": {"@type": "Person", "name": "Seth Black", "url": "https://www.linkedin.com/in/seth-black-tx"}, "publisher": {"@type": "Organization", "name": "Sethserver", "logo": {"@type": "ImageObject", "url": "https://www.sethserver.com/static/images/PaperAirplane512.png"}}, "description": "Learn how to connect your Replit app to Supabase PostgreSQL securely. Step-by-step guide covering connection strings, environment secrets, SSL configuration, and working code examples in Node.js and Python for building database-backed apps.", "articleSection": "Technology"}
{"@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [{"@type": "ListItem", "position": 1, "name": "sethserver", "item": "https://www.sethserver.com/"}, {"@type": "ListItem", "position": 2, "name": "Programming", "item": "https://www.sethserver.com/programming/"}, {"@type": "ListItem", "position": 3, "name": "How to Connect Replit to Supabase Postgres Database (Node.js & Python Guide)", "item": "https://www.sethserver.com/programming/connecting-replit-to-supabase-postgres.html"}]}
```
