An event ticketing system built with Node.js, Express, and MongoDB that allows users to purchase event tickets and generate QR codes for verification.
✅ User Authentication (Middleware-protected routes)
✅ Purchase Tickets with API endpoints
✅ Generate QR Codes for ticket validation
✅ Express-based REST API for easy integration
✅ MongoDB Database for storing ticket & event details
event-ticketing/
│── controllers/ # Contains business logic (purchaseTicket, etc.)
│── middleware/ # Middleware (authMiddleware for authentication)
│── models/ # Database models (User, Ticket, Event)
│── routes/ # Express routes (API endpoints)
│── server.js # Main entry point for the backend server
│── package.json # Dependencies and scripts
└── README.md # Project documentation
git clone https://github.com/yourusername/event-ticketing.git
cd event-ticketing
npm install
Create a .env
file in the root directory and add:
PORT=5000
MONGO_URI=mongodb+srv://yourusername:[email protected]/ticketing
JWT_SECRET=your_secret_key
npm start
Your backend will be running on http://localhost:5000.
Method | Endpoint | Description |
---|---|---|
POST | /api/auth/register |
Register a new user |
POST | /api/auth/login |
Login and get token |
Method | Endpoint | Description |
---|---|---|
POST | /api/tickets/generate-qrcode |
Generate ticket QR code |
POST /api/auth/register
{
"name": "John Doe",
"email": "[email protected]",
"password": "securepassword"
}
Response:
{
"message": "User registered successfully",
"token": "your_jwt_token"
}
POST /api/tickets/generate-qrcode
Headers: { "Authorization": "Bearer your_jwt_token" }
Body:
{
"event_id": "64bcd56f1a23bc9c",
"user_id": "64acd23f45fcd123"
}
Response:
{
"ticket_id": "64dd123f4bcd8912",
"qr_code": "qrcode_link_here"
}
-
Issue:
Cannot read properties of undefined (reading 'id')
✅ Solution: Ensureexpress.json()
is used inserver.js
:app.use(express.json()); app.use(express.urlencoded({ extended: true }));
-
Issue: API request body is empty
✅ Solution: Check if the request is sent withContent-Type: application/json
.
🔹 Stripe Payment Integration for ticket purchases
🔹 User Dashboard to manage booked tickets
🔹 Admin Panel for event management
Feel free to submit issues, pull requests, or feature requests.
This project is licensed under the MIT License.
🎉 Happy coding! Let me know if you have any issues!