Installation
Complete guide to setting up CodeNotify Server for development.
Prerequisites
Required Software
| Software | Version | Purpose |
|---|---|---|
| Node.js | >= 18.x | Runtime environment |
| npm | >= 9.x | Package manager |
| MongoDB | >= 6.x | Database |
| Git | Latest | Version control |
Verify Installation
bash
# Check Node.js version
node --version
# Should output: v18.x.x or higher
# Check npm version
npm --version
# Should output: 9.x.x or higher
# Check MongoDB
mongod --version
# Should output: db version v6.x.x or higherInstallation Steps
1. Clone the Repository
bash
git clone <repository-url>
cd CodeNotify2. Navigate to Server
bash
cd server3. Install Dependencies
bash
npm installThis will install all required packages:
- @nestjs/core - NestJS framework
- @nestjs/mongoose - MongoDB integration
- @nestjs/jwt - JWT authentication
- @nestjs/schedule - Cron jobs
- mongoose - MongoDB ODM
- zod - Schema validation
- bcrypt - Password hashing
- axios - HTTP client
- resend - Email service
4. Set Up MongoDB
Option A: Local MongoDB
bash
# Start MongoDB service
sudo systemctl start mongod
# Verify MongoDB is running
sudo systemctl status mongodOption B: MongoDB Atlas (Cloud)
- Create account at MongoDB Atlas
- Create a new cluster
- Get connection string
- Whitelist your IP address
5. Configure Environment Variables
Create .env file in the Server directory:
bash
cp .env.example .envEdit .env with your configuration:
bash
# Server Configuration
PORT=3000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://localhost:27017/codenotify
# Or for MongoDB Atlas:
# MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/codenotify
# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_EXPIRES_IN=15m
JWT_REFRESH_SECRET=your-super-secret-refresh-key-change-this-in-production
JWT_REFRESH_EXPIRES_IN=7d
# Contest Sync Configuration
CONTEST_SYNC_ENABLED=true
CONTEST_SYNC_INTERVAL=0 */6 * * *
CONTEST_CLEANUP_ENABLED=true
CONTEST_CLEANUP_DAYS=90
# Notification Configuration
NOTIFICATIONS_ENABLED=true
NOTIFICATION_WINDOW_HOURS=24
# Email Configuration (Resend)
RESEND_API_KEY=your-resend-api-key
EMAIL_FROM=noreply@codenotify.dev
# WhatsApp Configuration (Optional)
WHATSAPP_API_KEY=your-whatsapp-api-key
WHATSAPP_PHONE_NUMBER=+12345678906. Verify Installation
bash
# Build the project
npm run build
# Run tests
npm run test
# Check for linting errors
npm run lintProject Structure
Server/
├── src/
│ ├── auth/ # Authentication module
│ ├── users/ # User management
│ ├── contests/ # Contest management
│ ├── notifications/ # Notification system
│ ├── integrations/ # Platform adapters
│ │ └── platforms/
│ │ ├── codeforces/
│ │ ├── leetcode/
│ │ ├── codechef/
│ │ └── atcoder/
│ ├── common/ # Shared utilities
│ ├── config/ # Configuration
│ ├── database/ # Database setup
│ └── main.ts # Application entry
├── test/ # E2E tests
├── .env # Environment variables
├── .env.example # Environment template
├── package.json # Dependencies
├── tsconfig.json # TypeScript config
└── nest-cli.json # NestJS configRunning the Application
Development Mode
bash
npm run start:devThis starts the server with hot-reload enabled. The API will be available at:
http://localhost:3000Production Mode
bash
# Build the application
npm run build
# Start production server
npm run start:prodDebug Mode
bash
npm run start:debugDebugger will be available on port 9229.
Verify Installation
1. Check Server Status
Open browser and navigate to:
http://localhost:3000You should see the CodeNotify landing page with API status.
2. Test Health Endpoint
bash
curl http://localhost:3000/contests/healthExpected response:
json
{
"status": "ok",
"timestamp": "2024-02-15T10:00:00.000Z"
}3. Check Database Connection
The server logs should show:
[Nest] INFO [MongooseModule] Mongoose connected successfully
[Nest] INFO [NestApplication] Nest application successfully startedCommon Issues
Port Already in Use
bash
# Error: Port 3000 is already in use
# Solution: Change PORT in .env or kill the process
lsof -ti:3000 | xargs kill -9MongoDB Connection Failed
bash
# Error: MongooseServerSelectionError
# Solutions:
# 1. Verify MongoDB is running
sudo systemctl status mongod
# 2. Check MONGODB_URI in .env
# 3. Verify network connectivity (for Atlas)
# 4. Check IP whitelist (for Atlas)Missing Dependencies
bash
# Error: Cannot find module
# Solution: Reinstall dependencies
rm -rf node_modules package-lock.json
npm installEnvironment Variables Not Loaded
bash
# Error: JWT_SECRET is not defined
# Solution: Verify .env file exists and is in Server directory
ls -la .envDevelopment Tools
Recommended VS Code Extensions
- ESLint - Code linting
- Prettier - Code formatting
- Thunder Client - API testing
- MongoDB for VS Code - Database management
Useful Commands
bash
# Format code
npm run format
# Lint and fix
npm run lint
# Run tests with coverage
npm run test:cov
# Watch mode for tests
npm run test:watchNext Steps
Now that you have CodeNotify installed:
- Configuration - Configure advanced settings
- Quick Start - Make your first API request
- Architecture - Understand the system design
Troubleshooting
If you encounter issues:
- Check the Common Issues section
- Verify all prerequisites are installed
- Ensure environment variables are correctly set
- Check server logs for detailed error messages
- Consult the API Documentation
Production Deployment
For production deployment, see:
- Docker configuration
- Environment setup
- Security checklist
- Monitoring and logging

