Overview
This guide will walk you through setting up the Inmobiliaria API on your local development machine. You’ll install dependencies, configure the database, set up environment variables, and run the server.Prerequisites
Before you begin, ensure you have the following installed:Node.js
Version 24.13.1 or higher (LTS recommended)
PostgreSQL
Version 14 or higher
Git
For cloning the repository
npm or yarn
Package manager (included with Node.js)
The project requires Node.js v24.13.1. You can use nvm to manage Node.js versions easily.
Installation steps
Clone the repository
First, clone the repository and navigate to the project directory:If using nvm, install the required Node.js version:
Install dependencies
Install all required npm packages:This will install:
- Express.js v4.21.2 - Web framework
- Drizzle ORM v0.36.4 - Database ORM
- Better Auth v1.3.4 - Authentication
- Sharp v0.33.4 - Image processing
- Zod v3.25.1 - Schema validation
- PostgreSQL client - Database driver
- And other dependencies listed in
package.json
Set up PostgreSQL database
Create a new PostgreSQL database for the application:
Your PostgreSQL database is ready when you can connect to it successfully.
Configure environment variables
Create a
.env file in the project root with the following variables:.env
Required environment variables
| Variable | Description | Example |
|---|---|---|
DATABASE_URL | PostgreSQL connection string | postgresql://user:pass@localhost:5432/db |
BETTER_AUTH_SECRET | Secret key for auth (min 32 chars) | your-secret-key-min-32-chars-long |
BETTER_AUTH_URL | Backend URL for Better Auth | http://localhost:3000 |
FRONTEND_URL | Frontend URL for CORS | http://localhost:5173 |
Optional environment variables
| Variable | Description | Default |
|---|---|---|
PORT | Server port | 3000 |
NODE_ENV | Environment mode | development |
STORAGE_DRIVER | Storage backend (local/s3) | local |
UPLOAD_DIR | Local upload directory | uploads |
MAX_UPLOAD_SIZE_MB | Max file size in MB | 10 |
Run database migrations
Set up the database schema using Drizzle Kit:This creates all necessary tables:
users,accounts,sessions- Authenticationproperties- Property listingsproperty_types,property_subtypes- Property metadataoperation_types- Sale/Rent typesproperty_locations- Address dataproperty_images- Image metadataproperty_characteristics- Features and attributescurrencies,property_conditions,property_statuses- Reference data
All migration files are stored in
src/db/migrations/ for version control.Seed the database (optional)
Populate the database with sample data for development:This will create:
- Property types (departamento, casa, terreno, etc.)
- Operation types (venta, alquiler, alquiler-temporal)
- Currencies (USD, ARS, EUR)
- Property conditions and statuses
- Sample admin user (check console output for credentials)
- Sample properties with images
After seeding, you’ll see a confirmation message with the number of records created.
Start the development server
Run the server in development mode with hot reload:You should see output similar to:
Development tools
Available npm scripts
The project includes several useful scripts:package.json scripts
Drizzle Studio
Open a web-based database GUI:https://local.drizzle.studio where you can:
- Browse all database tables
- View and edit records
- Run queries
- Inspect relationships
Storage configuration
Local storage (default)
For development, local file storage is enabled by default:.env
uploads/ directory and served at http://localhost:3000/uploads/.
S3-compatible storage
For production or if you prefer cloud storage, configure S3:.env
- AWS S3 - Standard S3 storage
- Cloudflare R2 - S3-compatible, zero egress fees
- Backblaze B2 - S3-compatible, affordable storage
Images are automatically optimized and converted to WebP format with two variants: thumbnail (400px) and large (1200px).
Email configuration
The API uses Resend for transactional emails:.env
- Email verification during signup
- Password reset requests
- Contact form submissions
Troubleshooting
Database connection errors
Database connection errors
Error:
Failed to connect to databaseSolutions:- Verify PostgreSQL is running:
pg_isready - Check DATABASE_URL format:
postgresql://user:password@host:port/database - Ensure database exists:
psql -l - Check firewall/network settings
- Verify credentials are correct
Port already in use
Port already in use
Error:
EADDRINUSE: address already in use :::3000Solutions:- Change the PORT in
.env:PORT=3001 - Kill the process using port 3000:
- Use a different port temporarily:
Sharp installation issues
Sharp installation issues
Better Auth errors
Better Auth errors
Error: Error: Session/cookie issuesSolution:
BETTER_AUTH_SECRET is missing!Solution:
Ensure .env contains a secure secret (minimum 32 characters):- Check FRONTEND_URL matches your frontend’s origin
- Ensure cookies are enabled in your client
- In development, use
sameSite: 'lax'(automatic)
Migration errors
Migration errors
Error: Migration fails or schema conflictsSolutions:
- Drop and recreate database (development only):
- Check migration files in
src/db/migrations/ - Manually apply migrations:
Production build
To build and run the production version:Next steps
Quickstart guide
Make your first API call
Authentication
Learn about authentication flows
API reference
Explore all available endpoints
Deployment guide
Deploy to production