A robust Node.js/Express.js backend for the Coding Club application, providing APIs for user management, events, exams, and more.
- Features
- Tech Stack
- Getting Started
- API Documentation
- Project Structure
- Security Features
- Performance Optimizations
- Contributing
- User authentication and authorization (JWT-based)
- Admin and regular user roles
- Event management
- Exam creation and evaluation
- Faculty profiles
- Results tracking
- Real-time notifications
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (jsonwebtoken)
- Password Hashing: bcryptjs
- File Storage: Cloudinary
- Email: Nodemailer
- Real-time Communication: WebSockets (ws)
- Node.js 16.x or higher
- MongoDB (local or Atlas)
- npm or yarn
- Clone the repository
- Install dependencies
npm install
# or
yarn- Set up environment variables (see below)
- Start the development server
npm run dev
# or
yarn devCreate a .env file in the root directory with the following variables:
# Server
PORT=3030
NODE_ENV=development
# Database
MONGODB_URL=mongodb+srv://your-mongodb-connection-string
DB_NAME=coding_club
# JWT
ACCESS_TOKEN_SECRET=your-access-token-secret
ACCESS_TOKEN_EXPIRY=1d
REFRESH_TOKEN_SECRET=your-refresh-token-secret
REFRESH_TOKEN_EXPIRY=10d
# Admin
ADMINSECRETKEY=your-admin-secret-key
# CORS
CORS_ORIGIN=http://localhost:5173,https://your-frontend-domain.com
# Cloudinary (for file uploads)
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret
# Email (for notifications)
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=[email protected]
SMTP_PASS=your-email-passwordPOST /api/v1/users/signup
Request body:
{
"fullName": "John Doe",
"email": "[email protected]",
"password": "securepassword",
"phoneNumber": "1234567890",
"registrationNumber": "CSE123",
"branch": "CSE",
"semester": 5
}POST /api/v1/users/login
Request body:
{
"email": "[email protected]",
"password": "securepassword"
}GET /api/v1/events
Query parameters:
page: Page number (default: 1)limit: Items per page (default: 10)sortBy: Field to sort by (default: "date")sortOrder: Sort order ("asc" or "desc", default: "desc")category: Filter by categorystatus: Filter by statusisExam: Filter by exam type (true/false)skillLevel: Filter by skill level
GET /api/v1/events/:id
GET /api/v1/exams/:examId/responses
POST /api/v1/exams/:examId/responses/:responseId/evaluate
Request body:
{
"score": 85,
"feedback": "Good work, but could improve code organization",
"criteria": [
{
"criterionId": "criterion123",
"score": 4,
"comment": "Well implemented"
}
]
}src/
├── app.js # Express app setup
├── index.js # Entry point
├── constants.js # Application constants
├── controllers/ # Route controllers
├── db/ # Database connection
├── middlewares/ # Custom middlewares
├── models/ # Mongoose models
├── routes/ # API routes
└── utils/ # Utility functions
- JWT-based authentication
- Password hashing with bcrypt
- Rate limiting for sensitive endpoints
- CORS protection
- Input validation
- Error handling
- Database query optimization
- Pagination for list endpoints
- Request throttling
- Proper error handling
- Efficient MongoDB connection management
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request