3.6 KiB
3.6 KiB
| description |
|---|
| How to setup the backend development environment |
Setup Development Environment
Follow these steps to setup the E-Learning Platform backend on your local machine.
Prerequisites
- Node.js 18+ and npm
- Docker and Docker Compose
- Git
Step 1: Clone Repository
git clone <repository-url>
cd e-learning/Backend
Step 2: Install Dependencies
// turbo
npm install
Step 3: Setup Environment Variables
Copy example env file:
cp .env.example .env
Edit .env:
# Application
NODE_ENV=development
PORT=4000
APP_URL=http://localhost:4000
# Database
DATABASE_URL=postgresql://postgres:12345678@localhost:5432/elearning_dev
# Redis
REDIS_URL=redis://:dev_redis_password@localhost:6379
# MinIO/S3
S3_ENDPOINT=http://localhost:9000
S3_ACCESS_KEY=admin
S3_SECRET_KEY=12345678
S3_BUCKET_COURSES=courses
S3_BUCKET_VIDEOS=videos
S3_BUCKET_DOCUMENTS=documents
S3_BUCKET_IMAGES=images
S3_BUCKET_ATTACHMENTS=attachments
# JWT
JWT_SECRET=your-super-secret-jwt-key-change-in-production
JWT_EXPIRES_IN=24h
# Email (Mailhog)
SMTP_HOST=localhost
SMTP_PORT=1025
SMTP_FROM=noreply@elearning.local
Step 4: Start Docker Services
// turbo
docker compose up -d
This starts:
- PostgreSQL (port 5432)
- Redis (port 6379)
- MinIO (ports 9000, 9001)
- Mailhog (ports 1025, 8025)
- Adminer (port 8080)
Step 5: Run Database Migrations
// turbo
npx prisma migrate dev
Step 6: Seed Database
// turbo
npx prisma db seed
This creates:
- Default roles (Admin, Instructor, Student)
- Test users
- Sample categories
- Sample courses
Step 7: Start Development Server
// turbo
npm run dev
Server will start at http://localhost:4000
Step 8: Verify Setup
// turbo Test health endpoint:
curl http://localhost:4000/health
// turbo Test login:
curl -X POST http://localhost:4000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "admin123"}'
Access Services
| Service | URL | Credentials |
|---|---|---|
| Backend API | http://localhost:4000 | - |
| MinIO Console | http://localhost:9001 | admin / 12345678 |
| Mailhog UI | http://localhost:8025 | - |
| Adminer | http://localhost:8080 | postgres / 12345678 |
Development Commands
# Start dev server
npm run dev
# Run tests
npm test
# Run linter
npm run lint
# Format code
npm run format
# Generate Prisma Client
npx prisma generate
# View database in Prisma Studio
npx prisma studio
# Reset database (WARNING: deletes all data)
npx prisma migrate reset
Troubleshooting
Port Already in Use
# Find process using port
lsof -i :4000
# Kill process
kill -9 <PID>
Database Connection Error
# Check if PostgreSQL is running
docker ps | grep postgres
# Check logs
docker logs elearning-postgres
# Restart PostgreSQL
docker restart elearning-postgres
Prisma Client Error
# Regenerate client
npx prisma generate
# Clear node_modules
rm -rf node_modules
npm install
Checklist
- Node.js 18+ installed
- Docker installed and running
- Repository cloned
- Dependencies installed
.envfile configured- Docker services running
- Database migrated
- Database seeded
- Dev server running
- Health check passing
- Login test successful
Next Steps
- Read Backend Development Rules
- Follow Create API Endpoint workflow
- Review Agent Skills