You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RESTful API server for the GATE and UGC NET Practice Platform
📌 Overview
The Backend module is a Node.js/Express REST API server that handles all business logic, authentication, and database operations for the platform. It provides secure endpoints for both student and admin functionality.
✨ Features
🔐 Authentication - JWT-based user and admin authentication
👤 User Management - Registration, login, profile management
📝 Test Management - CRUD operations for tests and questions
📊 Results Tracking - Store and retrieve test results
📈 Statistics - User performance analytics
🛡️ Security - Password hashing with bcrypt
🏗️ Project Structure
Backend/
├── config/
│ └── connectDB.js # MongoDB connection configuration
├── controllers/
│ ├── adminController.js # Admin authentication and management logic
│ ├── authController.js # User authentication logic
│ ├── testController.js # Test management and submission logic
│ └── userController.js # User profile and statistics logic
├── middleware/
│ ├── adminAuth.js # Admin JWT authentication middleware
│ └── userAuth.js # User JWT authentication middleware (required & optional)
├── models/
│ ├── Test.js # Test and Question schema definition
│ ├── TestResult.js # Test result and answers schema
│ └── User.js # User profile and authentication schema
├── routes/
│ ├── adminRoutes.js # Admin-only API routes
│ ├── authRoutes.js # Public authentication routes
│ ├── testRoutes.js # Test CRUD and submission routes
│ └── userRoutes.js # User profile and stats routes
├── .env # Environment variables (not in git)
├── .gitignore # Git ignore rules
├── index.js # Express app entry point
├── package.json # Dependencies and scripts
└── README.md # Backend documentation
💻 Tech Stack
Technology
Version
Purpose
Node.js
Latest
Runtime environment
Express.js
5.2.1
Web framework
MongoDB
-
Database
Mongoose
9.2.2
MongoDB ODM
JWT
9.0.3
Authentication tokens
bcryptjs
3.0.3
Password hashing
CORS
2.8.6
Cross-origin support
dotenv
17.3.1
Environment variables
🚀 Getting Started
Prerequisites
Node.js (v18 or higher)
MongoDB (local or cloud instance like MongoDB Atlas)
Installation
# Navigate to Backend directorycd Backend
# Install dependencies
npm install
# Create .env file with the following variables:
PORT=8080
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/gate-ugcnet
JWT_SECRET=your_super_secret_jwt_key_2026
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=your_admin_password
# Start the server
npm start
# Server will be available at http://localhost:8080
Available Scripts
Script
Description
npm start
Start the server
🔗 API Endpoints
Authentication Routes (/api/auth)
Method
Endpoint
Description
Auth Required
Request Body
POST
/register
Register new user
No
{ email, password, name }
POST
/login
User login
No
{ email, password }
Admin Routes (/api/admin)
Method
Endpoint
Description
Auth Required
POST
/login
Admin login
No
GET
/verify
Verify admin token & get admin info
Admin Only
Test Routes (/api/tests)
Method
Endpoint
Description
Auth Required
POST
/create
Create new test
Admin Only
GET
/all
Get all tests (admin)
Admin Only
GET
/:id
Get test by ID
Admin Only
PUT
/update/:id
Update test
Admin Only
DELETE
/delete/:id
Delete test
Admin Only
GET
/active/list
Get all active tests
No
GET
/attempt/:testId
Get test for attempt
User Only
POST
/submit
Submit test answers
User Only
GET
/results/user
Get user's test results
User Only
GET
/stats/user
Get user's test statistics
User Only
User Routes (/api/users)
Method
Endpoint
Description
Auth Required
GET
/profile
Get user profile
User Only
PUT
/profile/update
Update user profile
User Only
GET
/stats
Get user statistics
User Only
🔐 Environment Variables
Variable
Description
Example
PORT
Server port
8080
MONGODB_URI
MongoDB connection string
mongodb+srv://user:pass@cluster.mongodb.net/db
JWT_SECRET
Secret key for JWT tokens
your_super_secret_jwt_key_2026
ADMIN_EMAIL
Admin login email
admin@example.com
ADMIN_PASSWORD
Admin login password
password123
🔒 Authentication
The API uses JWT (JSON Web Tokens) for authentication:
User Authentication: Users register/login and receive a JWT token
Admin Authentication: Admins login separately and receive an admin JWT token
Token Storage: Tokens are sent via HTTP headers: Authorization: Bearer <token>
Token Validation: Middleware validates tokens before allowing access to protected routes