A Node.js + Express + MongoDB API for managing events and bookings.
Users can register/login, view events, and book or cancel slots.
Admins can create, update, and delete events.
Hosted API: https://event-booking-backend-nc92.onrender.com
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose
- Auth: JWT, bcryptjs
- Validation & Middleware: Custom middlewares for auth & admin control
- User registration & login with JWT authentication
- Role‑based access (admin / user)
- Admins can add, edit, and delete events
- Users can view events
- Users can book and cancel event slots
- MongoDB Atlas as database
- Hosted on Render
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/auth/register |
Register new user | ❌ No |
| POST | /api/auth/login |
Login user | ❌ No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/event |
View all events | ❌ No |
| POST | /api/event |
Create event (admin) | ✅ Admin |
| PUT | /api/event/:id |
Update event (admin) | ✅ Admin |
| DELETE | /api/event/:id |
Delete event (admin) | ✅ Admin |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/bookings |
View bookings | ✅ Yes |
| POST | /api/bookings/:eventId |
Book an event | ✅ Yes |
| DELETE | /api/bookings/:eventId |
Cancel booking | ✅ Yes |
POST /api/auth/register
Body (JSON):
{
"name": "John Doe",
"email": "john@example.com",
"password": "123456",
"role": "user"
}POST /api/auth/login
Body (JSON):
{
"email": "john@example.com",
"password": "123456"
}Response will contain a JWT token; copy it.
For protected routes, send this header:
Authorization: Bearer your_jwt_token
GET /api/event
(No authentication required)
Returns a list of all available events.
POST /api/bookings/:eventId
Headers:
Authorization: Bearer your_jwt_token
Content-Type: application/json
GET /api/bookings
Headers:
Authorization: Bearer your_jwt_token
DELETE /api/bookings/:eventId
Headers:
Authorization: Bearer your_jwt_token
This API is deployed on Render: https://event-booking-backend-nc92.onrender.com
To get all events: https://event-booking-backend-nc92.onrender.com/api/event