View more posts
03-11-20216 minute read

Using Supabase in Replit

Table of contents is an awesome new browser based IDE where you can code alone or collaboratively with friends using their awesome multiplayer features! It's particularly useful for education, and sharing code examples with others.

They support a ton of different languages and execution environments and even recently introduced a simple key value store you can use to persist data.

As a Replit user, if you want to access larger amounts of data direct from your repl, or if you fancy accessing some super-powerful query tools, at some point you may want to start interacting with a relational database. Supabase is a good fit here; just like Replit, you don't need to worry about servers, and hosting, you can just click a few buttons and get a fully featured relational database which you can start communicating with directly from javacript, using supabase-js.

Here's how to start a Supabase + Node.js repl:

Sign up for and hit new repl in the top left


Select node.js, give it a name, and click Create repl


Import supabase's createClient method and hit run to install the required libs:

1const { createClient } = require('@supabase/supabase-js')

Setup a new Supabase project and grab the URL and anon key from Settings > API. Create the client in javascript using:

1const supabase = createClient(
2  '',
3  'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'


Now that supabase is connected you'll want to add some data to your db, you can grab any SQL dataset on the web, or make your own, but the fasted way to test is to open the SQL tab in the Supabase dashboard and click the Countries sample database and click Run.


From within your repl you can now query your countries table like:

1// .then() syntax
3  .from('countries')
4  .select('*')
5  .limit(5)
6  .then(console.log)
7  .catch(console.error)
9// or...
10// async/await syntax
11const main = async() => {
12  let { data, error } = supabase
13    .from('countries')
14    .select('*')
15    .limit(5)
17  if (error) {
18    console.log(error)
19    return
20  }
22  console.log(data)

Once this is working, if you want to learn more about the query interface you might want to try some of these challenges:

1// 1. List all the countries in Antarctica
2// 2. Fetch the iso3 code of the country with ID 3
3// 3. List the countries with 'Island' in the name
4// 4. Count the number of countries that start with 'Z' or 'Q'
5// 5. Fetch all the Countries where continents is null

There are full solutions provided in the video version of this blog, but some examples you may find useful are:

1// or
2const { data, error } = await supabase
3  .from('cities')
4  .select('name, country_id')
5  .or('id.eq.20,id.eq.30')
7// is
8const { data, error } = await supabase.from('cities').select('name, country_id').is('name', null)
10// in
11const { data, error } = await supabase
12  .from('cities')
13  .select('name, country_id')
14  .in('name', ['Rio de Janeiro', 'San Francisco'])
16// neq (not equal to)
17const { data, error } = await supabase
18  .from('cities')
19  .select('name, country_id')
20  .neq('name', 'The shire')
22// full docs here: /docs/reference/javascript/filter

We look forward to showing off some more Supabase + Replit examples.

You can find my example repl here:

Supabase has a free tier, head over to to get started.

Related articles
Protecting reserved roles with PostgreSQL Hooks
Developers stay up to date with
Using Supabase in Replit
Postgres as a CRON Server
Cracking PostgreSQL Interview Questions
View all posts
Last post

Developers stay up to date with

22 March 2021
Next post

Toad, a link shortener with simple APIs for low-coders

8 March 2021

Build in a weekend, scale to millions