Node.js · Express · MongoDB (Mongoose)
eventease-backend/
├── config/
│ └── db.js # MongoDB connection
├── controllers/
│ ├── authController.js # register, login, getMe
│ ├── eventController.js # CRUD + RSVP
│ └── userController.js # profiles, participants
├── middleware/
│ ├── auth.js # JWT protect + role guard
│ └── errorHandler.js # centralised error handler
├── models/
│ ├── User.js
│ ├── Event.js
│ └── RSVP.js
├── routes/
│ ├── auth.js
│ ├── events.js
│ └── users.js
├── .env.example
├── seed.js # sample data loader
└── server.js # app entry point
cd eventease-backend
npm installcp .env.example .env
# Edit .env — set MONGO_URI and JWT_SECRETmongod --dbpath /data/dbOr use a free MongoDB Atlas cluster and paste the connection string into MONGO_URI.
npm run seednpm run dev # development (nodemon)
npm start # productionServer runs at: http://localhost:5000
All endpoints are prefixed with /api.
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /auth/register | Public | Create account |
| POST | /auth/login | Public | Login → JWT token |
| GET | /auth/me | Private | Get logged-in user |
Register body:
{
"name": "Rahul Sharma",
"email": "rahul@student.com",
"password": "Secure@123",
"role": "student"
}Login body:
{ "email": "rahul@student.com", "password": "Secure@123" }Response includes a JWT token:
{ "success": true, "token": "eyJ...", "user": { ... } }| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /events | Public | List all events |
| GET | /events?category=tech | Public | Filter by category |
| GET | /events?search=hack | Public | Full-text search |
| GET | /events/:id | Public | Get single event |
| POST | /events | Organizer / Admin | Create event |
| PATCH | /events/:id | Owner / Admin | Update event |
| DELETE | /events/:id | Owner / Admin | Delete event |
| POST | /events/:id/rsvp | Logged-in user | Register for event |
| DELETE | /events/:id/rsvp | Logged-in user | Cancel RSVP |
Create event body:
{
"name": "HackSphere 2025",
"category": "tech",
"description": "36-hour hackathon...",
"date": "2025-09-12",
"time": "10:00 AM",
"venue": "Innovation Lab, Block C",
"maxSeats": 200
}| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /users/my-events | Private (any) | My registered events |
| GET | /users/participants | Organizer / Admin | All RSVP records |
| PATCH | /users/profile | Private (any) | Update name / avatar |
| GET | /users | Admin only | List all users |
| GET | /users/:id | Admin only | Get user by ID |
| DELETE | /users/:id | Admin only | Delete user |
Send the JWT in every protected request:
Authorization: Bearer <token>
| Role | Can do |
|---|---|
| student | Browse events, RSVP, view own events |
| organizer | All student actions + create/edit/delete own events + view participants |
| admin | Full access to all resources |
In your index.html, replace the static handleLogin with:
const API = 'http://localhost:5000/api';
async function handleLogin() {
const email = document.getElementById('login-email').value;
const password = document.getElementById('login-password').value;
const role = document.getElementById('login-role').value;
const res = await fetch(`${API}/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
});
const data = await res.json();
if (!data.success) { alert(data.message); return; }
localStorage.setItem('token', data.token);
localStorage.setItem('user', JSON.stringify(data.user));
// …continue with your existing UI logic
}
async function fetchEvents(category = 'all') {
const url = category === 'all'
? `${API}/events`
: `${API}/events?category=${category}`;
const data = await (await fetch(url)).json();
return data.events;
}
async function rsvpEvent(eventId) {
const token = localStorage.getItem('token');
const res = await fetch(`${API}/events/${eventId}/rsvp`, {
method: 'POST',
headers: { Authorization: `Bearer ${token}` },
});
return res.json();
}| Role | Password | |
|---|---|---|
| Admin | admin@eventease.com | Admin@123 |
| Organizer | organizer@eventease.com | Org@12345 |
| Student | rahul@student.com | Student@1 |
| Student | priya@student.com | Student@2 |
- Runtime: Node.js 18+
- Framework: Express 4
- Database: MongoDB via Mongoose 8
- Auth: JWT (jsonwebtoken) + bcryptjs
- Validation: mongoose built-in + express-validator ready
- Logging: morgan (dev mode)