The error ECONNREFUSED ::1:5432 means PostgreSQL is not running or not accessible.
macOS (using Homebrew):
brew install postgresql@14
# or
brew install postgresqlLinux (Ubuntu/Debian):
sudo apt-get update
sudo apt-get install postgresql postgresql-contribWindows: Download and install from https://www.postgresql.org/download/windows/
macOS:
# Start PostgreSQL service
brew services start postgresql
# or
pg_ctl -D /usr/local/var/postgres startLinux:
sudo systemctl start postgresql
# Enable auto-start on boot
sudo systemctl enable postgresqlWindows: Start PostgreSQL service from Services panel or use pgAdmin.
# Create the database
createdb ota_console
# Or using psql
psql postgres
CREATE DATABASE ota_console;
\qCreate/update backend/.env:
macOS (Homebrew) - Default user is your macOS username:
# Database Configuration (macOS with Homebrew)
DB_HOST=localhost
DB_PORT=5432
DB_NAME=ota_console
DB_USER=punithmanthri # Your macOS username (usually no password needed)
DB_PASSWORD=
# Or use connection string
# DATABASE_URL=postgresql://punithmanthri@localhost:5432/ota_consoleLinux/Windows - Typically uses 'postgres' user:
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=ota_console
DB_USER=postgres
DB_PASSWORD=your_password
# Or use connection string
# DATABASE_URL=postgresql://postgres:password@localhost:5432/ota_consoleJWT_SECRET=your-super-secret-jwt-key-change-in-production JWT_EXPIRES_IN=7d
PORT=3001 NODE_ENV=development
### Step 5: Run Database Migrations
```bash
cd backend
npm run migrate
This will create all necessary tables (users, versions, update_logs).
# Test database connection
psql -d ota_console -c "SELECT version();"Or check the health endpoint:
curl http://localhost:3001/healthcd backend
npm startYou should see:
✓ Connected to PostgreSQL database
Server running on port 3001
Environment: development
macOS:
# Check if PostgreSQL is running
pg_isready
# Check logs
tail -f /usr/local/var/log/postgres.logLinux:
# Check status
sudo systemctl status postgresql
# Check logs
sudo journalctl -u postgresql -fIf you get permission errors, you may need to create a user:
# Create postgres user (if needed)
createuser -s postgresIf port 5432 is already in use:
- Find the process:
lsof -i :5432 - Kill it:
kill -9 <PID> - Or change PostgreSQL port in
postgresql.conf
If using DATABASE_URL, format is:
postgresql://username:password@host:port/database
Example:
postgresql://postgres:mypassword@localhost:5432/ota_console
If you have Docker installed:
# Run PostgreSQL in Docker
docker run --name ota-postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=ota_console \
-p 5432:5432 \
-d postgres:14
# Then update .env:
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/ota_console- ✅ PostgreSQL is running
- ✅ Database
ota_consoleexists - ✅ Migrations have been run
- ✅ Backend server starts without errors
- ✅ Health endpoint returns
"database": "connected" - ✅ Can register/login through frontend