DEV Community

Cathy Lai
Cathy Lai

Posted on

[MyNextHome] Server Backend to add Supabase!

So! A plain server backend (in NodeJS) to talk to real estate's site (TradeMe) is working with real data :)

The next step is to put them in a structured, modern way. Time to play with Supabase, the popular backend database. I'm starting with one table for now.

Current State Analysis

  • Express.js backend fetching open homes from TradeMe API
  • Data is fetched on-demand from TradeMe
  • Environment variables already configured via dotenv
  • Two endpoints: /api/open-homes and /api/open-homes/:id

Steps!

  1. Install @supabase/supabase-js
  2. Create Supabase project and get credentials
  3. Set up database schema in Supabase dashboard
  4. Create config/supabase.js for client initialization
  5. Create lib/database.js with CRUD functions
  6. Update index.js to integrate database calls
  7. Add sync logic (on-demand for now)
  8. Test endpoints with database integration

Sketch new directory structure

househunt-backend/
├── config/
│   └── supabase.js          # Supabase client initialization
├── lib/
│   └── database.js          # Database helper functions
├── services/
│   └── syncService.js       # TradeMe sync logic
├── index.js                 # Main Express app (updated)
├── package.json             # Updated with @supabase/supabase-js
└── .env                     # Updated with Supabase credentials
Enter fullscreen mode Exit fullscreen mode

Table Structure

open_homes table:
    - `id` (uuid, primary key)
    - `listing_id` (text, unique) - TradeMe listing ID
    - `title` (text)
    - `location` (text)
    - `bedrooms` (integer)
    - `bathrooms` (integer)
    - `open_home_time` (timestamp)
    - `price` (text)
    - `picture_href` (text)
    - `trademe_data` (jsonb) - store full TradeMe response
    - `created_at` (timestamp)
    - `updated_at` (timestamp)
Enter fullscreen mode Exit fullscreen mode

Benefits of Adding Supabase

  • Faster responses (cached data)
  • Reduced TradeMe API calls
  • Historical data tracking
  • User features (favorites, search history)
  • Real-time updates
  • Scalable PostgreSQL database
  • Built-in authentication (if needed)

Coming back to do this tomorrow morning!

Top comments (0)