# Environment Setup ## Quick Setup (RECOMMENDED: Direct PostgreSQL Connection) For best performance with heavy SQL queries, use direct PostgreSQL connection: Create a `.env` file in the `backend` directory with the following content: ```env # Direct PostgreSQL Connection (RECOMMENDED - Faster & More Reliable) # Get this from: Supabase Dashboard > Settings > Database > Connection String (URI) DATABASE_URL=postgresql://postgres:[password]@db.[project-ref].supabase.co:5432/postgres # Optional: Supabase Client (for simple queries) # Get from: Supabase Dashboard > Settings > API SUPABASE_URL=https://your-project-ref.supabase.co SUPABASE_SERVICE_KEY=your_service_role_key_here # Server Configuration PORT=3010 NODE_ENV=development # CORS Configuration CORS_ORIGIN=http://localhost:5173 ``` ## Alternative Setup (Supabase Client Only) If you prefer to use only Supabase client (not recommended for heavy queries): ```env # Supabase Configuration SUPABASE_URL=https://your-project-ref.supabase.co SUPABASE_ANON_KEY=your_anon_key_here # Supabase Service Key (REQUIRED for backend operations) # Get this from: Supabase Dashboard > Settings > API > service_role key SUPABASE_SERVICE_KEY=your_service_role_key_here # Server Configuration PORT=3010 NODE_ENV=development # CORS Configuration CORS_ORIGIN=http://localhost:5173 ``` ## Important Notes 1. **DATABASE_URL (RECOMMENDED)** - Direct PostgreSQL connection - Faster for heavy SQL queries - No API key issues - Get from: Supabase Dashboard > Settings > Database > Connection String (URI) - Replace `[password]` with your database password - Replace `[project-ref]` with your project reference 2. **SUPABASE_SERVICE_KEY** - Required if using Supabase client - Go to your Supabase Dashboard - Navigate to Settings > API - Copy the `service_role` key (not the `anon` key) - ⚠️ **Use service_role key, NOT anon key** for backend operations 3. **Never commit `.env` files** - They are in `.gitignore` for security 4. **Troubleshooting**: If you get "Invalid API key" errors, see `TROUBLESHOOTING.md` ## Verification After creating the `.env` file, test the connection: ```bash cd backend npm install npm run dev ``` You should see: `✅ Database connection successful`