Node.js/Express backend API for MatchPlay pickleball league management with PostgreSQL database.
- Node.js 18+
- PostgreSQL database (local or Render)
- npm or yarn
# Install dependencies
npm install
# Set up environment variables (see below)
# Then initialize database
npm run db:initCreate a .env file or set environment variables:
DATABASE_URL=postgresql://user:password@host:5432/database
NODE_ENV=development
PORT=3001# Run with auto-reload
npm run dev
# Or run without auto-reload
npm startServer will run on http://localhost:3001
npm run db:initThis creates all tables, indexes, and inserts sample data.
- PostgreSQL with connection pooling
- Tables: athletes, gamedays, gameday_athletes, matches
- Indexes: Optimized for common queries
- Sample data: 12 athletes pre-loaded
See database/README.md for details.
For production deployment and detailed setup: DATABASE_SETUP.md
GET /api/gamedays- Get all game daysGET /api/gamedays/:id- Get single game dayPOST /api/gamedays- Create new game dayPUT /api/gamedays/:id- Update game dayDELETE /api/gamedays/:id- Delete game dayGET /api/gamedays/:id/athletes- Get athletes for game dayPOST /api/gamedays/:id/athletes- Add athletes to game dayDELETE /api/gamedays/:id/athletes/:athleteId- Remove athlete from game dayGET /api/gamedays/:id/draw-preview- Preview group allocationPOST /api/gamedays/:id/generate-draw- Generate match drawPOST /api/gamedays/:id/generate-next-round- Generate next roundPOST /api/gamedays/:id/cancel-draw- Cancel draw and delete matchesGET /api/gamedays/:id/matches- Get matches for game dayGET /api/gamedays/:id/leaderboard- Get group leaderboard
GET /api/athletes- Get all athletesGET /api/athletes/:id- Get single athletePOST /api/athletes- Create new athletePUT /api/athletes/:id- Update athleteDELETE /api/athletes/:id- Delete athlete
GET /api/matches/:id- Get single matchPUT /api/matches/:id/score- Update match scorePUT /api/matches/:id/status- Update match status
GET /api/leaderboard- Get overall leaderboard
GET /health- Server health check
backend/
├── database/ # Database module
│ ├── db.js # Connection pool
│ ├── queries.js # All database queries
│ ├── schema.sql # Database schema
│ ├── init.js # Initialization script
│ └── README.md # Database documentation
├── routes/ # API route handlers
│ ├── athletes.js
│ ├── gamedays.js
│ ├── matches.js
│ └── leaderboard.js
├── server.js # Express app entry point
├── package.json
└── DATABASE_SETUP.md # Database setup guide
- Runtime: Node.js
- Framework: Express.js
- Database: PostgreSQL with
pgdriver - Architecture: RESTful API
- Deployment: Render.com
- All routes use async/await
- Database queries are in
database/queries.js - Connection pooling for performance
- Auto-updating timestamps on updates
- Comprehensive error handling
# Test database connection
node -e "import('./database/db.js').then(db => db.query('SELECT NOW()'))"
# Test API endpoints
curl http://localhost:3001/health
curl http://localhost:3001/api/athletesSee DEPLOYMENT_GUIDE.md for deploying to Render.com.
Key steps:
- Create PostgreSQL database on Render
- Deploy backend with
DATABASE_URLenvironment variable - Run
npm run db:initto initialize database
- Check
DATABASE_URLis set correctly - Verify database is running
- Ensure correct SSL settings for production
- Run
npm run db:initto create tables
- Change
PORTenvironment variable - Or kill process:
npx kill-port 3001
MIT