Database Setup Guide
Error You're Seeing
No database host or connection string was setThis means the DATABASE_URL environment variable is missing or not configured.
Quick Fix
Option 1: Use Neon (Recommended for Development)
-
Create a Neon account:
- Go to https://console.neon.tech (opens in a new tab)
- Sign up (free tier available)
-
Create a new project:
- Click "New Project"
- Choose PostgreSQL
- Name it "optare-dev"
- Click "Create Project"
-
Get your connection string:
- Go to "Connection string"
- Copy the full URL (looks like:
postgresql://user:password@host/database)
-
Update
.envfile:DATABASE_URL=postgresql://user:password@host/database -
Restart the dev server:
# Stop current server (Ctrl+C) pnpm run dev
Option 2: Use Local PostgreSQL
-
Install PostgreSQL:
- Windows: https://www.postgresql.org/download/windows/ (opens in a new tab)
- Mac:
brew install postgresql - Linux:
sudo apt-get install postgresql
-
Start PostgreSQL:
# Windows pg_ctl -D "C:\Program Files\PostgreSQL\15\data" start # Mac brew services start postgresql # Linux sudo service postgresql start -
Create a database:
createdb optare_dev -
Update
.envfile:DATABASE_URL=postgresql://postgres:password@localhost:5432/optare_dev -
Restart the dev server:
pnpm run dev
Verify Connection
After setting DATABASE_URL, run:
pnpm run devYou should see:
✓ Local: http://localhost:5173/If you still see the database error, check:
-
Is DATABASE_URL set?
echo $DATABASE_URL -
Is the connection string correct?
- Format:
postgresql://user:password@host:port/database - No spaces or special characters
- Format:
-
Is the database running?
- For Neon: Check https://console.neon.tech (opens in a new tab)
- For local: Run
psql -U postgresto test
Environment Variables Needed
Required
DATABASE_URL- PostgreSQL connection string
Recommended
BETTER_AUTH_SECRET- Random 32+ character stringBETTER_AUTH_URL-http://localhost:5173for dev
Optional
RESEND_API_KEY- For email (get from https://resend.com (opens in a new tab))REDIS_URL- For caching (default:redis://localhost:6379)
Generate JWT Keys (Optional)
If you need to generate JWT keys for OAuth token exchange:
node -e "const crypto = require('crypto'); const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', { modulusLength: 2048, publicKeyEncoding: { type: 'spki', format: 'pem' }, privateKeyEncoding: { type: 'pkcs8', format: 'pem' } }); console.log('Private Key:\n', privateKey); console.log('\nPublic Key:\n', publicKey);"Copy the output to .env:
JWT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"
JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----"Troubleshooting
Error: "Connection refused"
- Database is not running
- Check if PostgreSQL service is started
- For Neon: Check internet connection
Error: "Authentication failed"
- Wrong password in connection string
- Check username and password
- For Neon: Copy the full connection string from console
Error: "Database does not exist"
- Database hasn't been created yet
- For local: Run
createdb optare_dev - For Neon: Create a new project
Error: "No such file or directory"
.envfile not found- Create
.envin project root - Copy from
.env.example
Next Steps
- ✅ Set up database (Neon or local PostgreSQL)
- ✅ Add
DATABASE_URLto.env - ✅ Run
pnpm run dev - ✅ Test login at http://localhost:5173/login (opens in a new tab)
Production Deployment
For production, use:
-
Neon (Recommended):
- Serverless PostgreSQL
- Auto-scaling
- Free tier available
- https://neon.tech (opens in a new tab)
-
AWS RDS:
- Managed PostgreSQL
- High availability
- https://aws.amazon.com/rds/ (opens in a new tab)
-
DigitalOcean:
- Managed databases
- Simple setup
- https://www.digitalocean.com/products/managed-databases/ (opens in a new tab)
Get the production connection string and add to your deployment environment variables.
Support
If you're still having issues:
- Check
.envfile exists in project root - Verify
DATABASE_URLis set correctly - Test database connection manually
- Check database logs for errors
- Restart the dev server
Let me know if you need help! 🚀