A minimal movie seat booking app with JWT authentication and PostgreSQL-backed seat reservation.
- Register / Login
- Browse seats
- Book a seat (protected route)
- Auth page:
GET /(orGET /register) - Booking page:
GET /booking
- Node.js, Express
- PostgreSQL (
pg) - JWT (
jsonwebtoken) - Simple HTML UI:
register.html,index.html
- Node.js (LTS recommended)
- Yarn
- A PostgreSQL database (local or hosted)
yarn installCreate a .env file in the project root.
| Variable | Required | Example | Notes |
|---|---|---|---|
PORT |
no | 8080 |
Server port |
DATABASE_URL |
yes | postgresql://user:pass@host:5432/db |
PostgreSQL connection string |
JWT_ACCESS_SECRET |
yes | a-very-long-random-secret |
Keep it private |
JWT_ACCESS_EXPIRES_IN |
no | 15m |
Defaults to 15m |
CORS_ORIGIN |
no | http://localhost:5173 |
Only needed if you call APIs from a different origin |
NODE_ENV |
no | development |
Enables secure cookies only in production |
Example .env:
PORT=8080
DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/DBNAME
JWT_ACCESS_SECRET=replace_me_with_a_long_random_secret
JWT_ACCESS_EXPIRES_IN=15m
# Optional (only if using a separate frontend origin)
# CORS_ORIGIN=http://localhost:5173
# NODE_ENV=developmentyarn startOpen:
http://localhost:8080/for Register/Loginhttp://localhost:8080/bookingfor seat booking
Base URL: http://localhost:8080
{
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"password": "password123"
}Returns JSON containing token and sets a token httpOnly cookie.
{
"email": "[email protected]",
"password": "password123"
}Returns JSON containing token and sets a token httpOnly cookie.
Returns all seats.
Books a seat by id for the authenticated user.
Protected routes accept the JWT in either form:
- Authorization header:
Authorization: Bearer <JWT_TOKEN>- Cookie:
token=<JWT_TOKEN>(httpOnly cookie)
The bundled booking UI uses localStorage and sends the JWT via the Authorization header.
This project expects at minimum:
userstable with columns like:id,"first name",last_name,email,password
seatstable with columns like:id,is_booked(boolean),name(booked-by)
index.mjs— Express server bootstrap + routesmodules/auth/*— register/login + auth middlewaremodules/TicketBookingService/*— seat list + bookingcommon/utils/*— DB + JWT helpersregister.html,index.html— UI pages
- 401 on booking
- Ensure you’re sending
Authorization: Bearer <token>or that thetokencookie is present.
- Ensure you’re sending
- Database connection errors
- Verify
DATABASE_URLand that your DB host is reachable (DNS/network).
- Verify
MIT