2.2 KiB
2.2 KiB
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:
# 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):
# 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
-
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
-
SUPABASE_SERVICE_KEY - Required if using Supabase client
- Go to your Supabase Dashboard
- Navigate to Settings > API
- Copy the
service_rolekey (not theanonkey) - ⚠️ Use service_role key, NOT anon key for backend operations
-
Never commit
.envfiles - They are in.gitignorefor security -
Troubleshooting: If you get "Invalid API key" errors, see
TROUBLESHOOTING.md
Verification
After creating the .env file, test the connection:
cd backend
npm install
npm run dev
You should see: ✅ Database connection successful