A Node.js REST API for managing events, tickets, reservations, and discounts, built with Express and PostgreSQL.
- User registration and authentication (JWT)
- Organizer and attendee roles
- Event creation, update, deletion (organizer-only)
- Ticket type management (CRUD)
- Ticket reservation and purchase (with discount codes)
- Automatic expiration of unpaid reservations (via cron)
- Discount code management (admin/organizer)
- Data validation with Joi
- Database migrations with Knex
- express – Web framework for building REST APIs
- pg – PostgreSQL database driver
- dotenv – Loads environment variables from
.envfile - jsonwebtoken – Handles JWT-based authentication
- bcryptjs – Securely hashes passwords
- cors – Enables Cross-Origin Resource Sharing
- joi – Schema validation for request bodies
- node-cron – Schedules tasks (e.g. ticket expiration checks)
- nodemon – Auto-restarts the server on file changes (development)
- knex – SQL query builder, used for migrations and seeders
Clone the repository and install dependencies:
npm installCreate a .env file in the root directory with your PostgreSQL and JWT settings:
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=your_db_name
JWT_SECRET=your_jwt_secret
Migration files are located in the migrations directory.
To create all the tables, run:
npx knex migrate:latestAlternatively, you can use the raw SQL in query.sql.
Start the server in development mode:
npm startThe API will be available at http://localhost:3000.
POST /api/auth/register/organizer– Register as organizerPOST /api/auth/register/attendee– Register as attendeePOST /api/auth/login– LoginDELETE /api/auth/delete-organizer/:userId– Delete organizer by user IDDELETE /api/auth/delete-attendee/:userId– Delete attendee by user IDPUT /api/auth/update-attendee/:userId– Update attendee by user IDPUT /api/auth/update-organizer/:userId– Update attendee by user ID
POST /api/events/create-events– Create event (organizer only)GET /api/events/events– List all eventsPUT /api/events/update-events/:eventId– Update event (organizer only)DELETE /api/events/delete-events/:eventId– Delete event (organizer only)GET /api/events/get-events/:eventId– Get event details
POST /api/ticket/createTicket– Create ticket typeGET /api/ticket/getTicket/:id– Get ticket type by IDGET /api/ticket/:event_id/ticket-types– List ticket types for eventPUT /api/ticket/updateTicket/:id– Update ticket typeDELETE /api/ticket/deleteTicket/:id– Delete ticket typeGET /api/ticket/:id/availability– Check ticket availabilityPOST /api/ticket/purchase-ticket– Purchase ticketPOST /api/ticket/reservation– Reserve ticket
POST /api/admin/discount/create– Create discount code
Unpaid reservations expire automatically (checked every hour by cron). Expired reservations release tickets back to availability.
All input is validated using Joi schemas in the validations directory.
MIT