A simple backend service in Node.js/TypeScript for managing movies, showtimes and seat reservations.
- User signup, login and role-based access via JWT
- CRUD operations for movies (admin only)
- CRUD operations for showtimes (admin only)
- List movies and their showtimes
- Check available seats and make/cancel reservations
- Node.js with TypeScript
- Express.js - Web framework
- Sequelize - ORM for PostgreSQL
- JWT - Authentication
- bcrypt - Password hashing
- PostgreSQL - Database
- Node.js 18+ or higher
- npm or yarn
- PostgreSQL database
-
Clone the repository:
git clone <repository-url> cd ticketmonster/nodejs
-
Install dependencies:
npm install
-
Copy
.env.exampleto.envand update settings:cp .env.example .env
-
Build the TypeScript project:
npm run build
-
Set up the database (seed with initial data):
npm run db:setup
-
Start the application:
# Development mode (with hot reload) npm run dev # Production mode npm start
The server listens by default on :3232.
npm run build- Compile TypeScript to JavaScriptnpm run dev- Start development server with hot reloadnpm start- Start production servernpm run seed- Seed database with initial datanpm run db:reset- Reset database (clear all data)npm run db:setup- Set up database with initial data
To run both the API and a PostgreSQL database with Docker:
docker-compose up -dThis will:
- Build the Node.js application
- Start the service on port
3232 - Spin up PostgreSQL on port
5432 - Automatically create the database schema
To stop and remove containers:
docker-compose downThe application uses the following environment variables (see .env.example):
DB_HOST=db # Database host (use 'localhost' for local development)
DB_PORT=5432 # Database port
DB_USER=postgres # Database username
DB_PASSWORD=postgres # Database password
DB_NAME=postgres # Database name
JWT_SECRET=your_jwt_secret # JWT secret key (change this!)
DB_SSLMODE=disable # Database SSL mode├── src/
│ ├── server.ts # Main application entry point
│ ├── config/
│ │ └── database.ts # Database configuration
│ ├── controllers/ # Route handlers
│ │ ├── authController.ts
│ │ ├── movieController.ts
│ │ ├── reservationController.ts
│ │ └── showtimeController.ts
│ ├── middleware/ # Custom middleware
│ │ ├── adminMiddleware.ts
│ │ └── authMiddleware.ts
│ ├── models/ # Sequelize models
│ │ ├── index.ts
│ │ ├── Movie.ts
│ │ ├── Reservation.ts
│ │ ├── Showtime.ts
│ │ └── User.ts
│ ├── routes/ # Route definitions
│ │ └── index.ts
│ └── services/ # Business logic layer
│ ├── authService.ts
│ ├── movieService.ts
│ ├── reservationService.ts
│ └── showtimeService.ts
├── scripts/ # Database scripts
│ ├── reset.ts # Reset database
│ └── seed.ts # Seed initial data
├── docker-compose.yml # Docker configuration
├── Dockerfile # Docker build instructions
├── package.json # Dependencies and scripts
└── tsconfig.json # TypeScript configuration
Public
Method Endpoint Description POST /api/signupRegister a new user POST /api/loginAuthenticate user GET /api/moviesList all movies User (authenticated)
Method Endpoint Description GET /api/user/reservationsList current user's reservations POST /api/reservationsCreate a new reservation DELETE /api/reservations/:reservationIdCancel a reservation GET /api/showtimes/:showtimeId/seatsGet available seats GET /api/movies/:movieID/showtimesList showtimes for a movie Admin
Method Endpoint Description POST /api/admin/moviesCreate a movie PUT /api/admin/movies/:movieIdUpdate a movie DELETE /api/admin/movies/:movieIdDelete a movie GET /api/admin/reservationsList all reservations POST /api/admin/users/:userId/promotePromote a user to admin POST /api/admin/showtimesCreate a showtime PUT /api/admin/showtimes/:showtimeIdUpdate a showtime DELETE /api/admin/showtimes/:showtimeIdDelete a showtime
- Make sure PostgreSQL is running locally
- Update
.envfile with local database settings:DB_HOST=localhost DB_PORT=5432 DB_USER=your_username DB_PASSWORD=your_password DB_NAME=ticketmonster
- Run in development mode:
npm run dev
- Reset database:
npm run db:reset(⚠️ This will delete all data) - Seed database:
npm run db:setup(Creates initial admin user and sample data)
The API uses JWT tokens for authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>After running npm run db:setup, you can login with:
- Email: [email protected]
- Password: admin123
You can test the API using curl or any HTTP client:
# Register a new user
curl -X POST http://localhost:3232/api/signup \
-H "Content-Type: application/json" \
-d '{"username":"user","email":"[email protected]","password":"password123"}'
# Login
curl -X POST http://localhost:3232/api/login \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"password123"}'
# Get movies (public endpoint)
curl http://localhost:3232/api/movies