This project is a TypeScript-based application that utilizes environment variables for configuration. It provides various API routes and endpoints to perform specific tasks. The project structure includes TypeScript files located in the src
directory and a configuration file named config.env
.
-
The 'generate.bat' batch file streamlines the process of generating and inserting test data into your local database, simplifying API testing efforts.
-
Start the application with PM2 in clustered mode:
pm2 start src/server.ts --name "express-cluster-ts" --watch --interpreter ts-node
-
After initiating the clustered mode, run the application [you can run it directly without initiating clustered mode] :
npm run start
The project expects the following environment variables to be defined in the src/config.env
file:
-
NODE_ENV
: development or production, this will affect logging middleware, smpt email settings and the way errors are sent (prod includes stack trace) -
PORT
: The port number on which the server will run. -
DB_LOCAL
: The hostname of the database server. (local) -
JWT_SECRET
: The secret key used for JSON Web Token (JWT) authentication. -
JWT_EXPIRES_IN
: JWT expires in 'xd' format (90d=90days) -
FROM_EMAIL
: server sender email -
PRODUCTION_SMPT_HOST
: host name of the production smpt -
PRODUCTION_SMPT_USER
: smpt user -
PRODUCTION_SMPT_PASSWORD
: smpt password -
DEVELOPMENT_SMPT_HOST
: host name of the development smpt -
DEVELOPMENT_SMPT_USER
: dev smpt user -
DEVELOPMENT_SMPT_PASSWORD
: dev smpt password
- GET /api/v1/tours: Get all tours.
- Controller:
getAllTours
- Controller:
- GET /api/v1/tours/:id: Get a tour by ID.
- Controller:
getTourById
- Controller:
- POST /api/v1/tours: Create a new tour.
- Controller:
createTourById
- Controller:
- PATCH /api/v1/tours/:id: Update a tour by ID.
- Controller:
UpdatePatchTour
- Controller:
- DELETE /api/v1/tours/:id: Delete a tour by ID.
- Controller:
deleteTourById
- Controller:
- GET /api/v1/tours/top5: Get top 5 tours.
- Controller:
top5Tours
- Controller:
- GET /api/v1/tours/stats: Get tour statistics.
- Controller:
getToursStats
- Controller:
- GET /api/v1/tours/plan/:year: Get yearly plan.
- Controller:
getYearlyPlan
- Controller:
- GET /api/v1/tours-within/:distance/center/:latlng/unit/:unit: Get tours within a certain distance.
- Controller:
getToursWithin
- Controller:
- GET /api/v1/tours/distances/:latlng/unit/:unit: Get distances of tours.
- Controller:
getDistances
- Controller:
- GET /api/v1/users: Get all users.
- Controller:
getAllUsers
- Controller:
- GET /api/v1/users/:id: Get a user by ID.
- Controller:
getUserById
- Controller:
- POST /api/v1/users: Create a new user.
- Controller:
createUserById
- Controller:
- PATCH /api/v1/users/:id: Update a user by ID.
- Controller:
updateUser
- Controller:
- DELETE /api/v1/users/:id: Delete a user by ID.
- Controller:
deleteUserById
- Controller:
- PATCH /api/v1/users/updateMe: Update logged-in user details.
- Controller:
updateMe
- Controller:
- DELETE /api/v1/users/deleteMe: Deactivate logged-in user.
- Controller:
deleteMe
- Controller:
- GET /api/v1/users/me: Get logged-in user information.
- Controller:
getMe
- Controller:
- GET /api/v1/reviews: Get all reviews.
- Controller:
getAllReviews
- Controller:
- POST /api/v1/reviews: Create a new review.
- Controller:
createReview
- Controller:
- PATCH /api/v1/reviews/:id: Update a review by ID.
- Controller:
updateReview
- Controller:
- DELETE /api/v1/reviews/:id: Delete a review by ID.
- Controller:
deleteReviewById
- Controller:
- GET /api/v1/reviews/:id: Get a review by ID.
- Controller:
getReviewById
- Controller:
- POST /api/v1/bookings: Create a new booking.
- Controller:
createBooking
- Controller:
- GET /api/v1/bookings: Get all bookings.
- Controller:
getAllBookings
- Controller:
- GET /base: Render base view.
- Controller:
baseController
- Controller:
- GET /overview: Render overview view.
- Controller:
overviewController
- Controller:
- Tour Model:
Tour
- User Model:
User
- Review Model:
Review
- Booking Model:
Booking
- Error Handling:
AppError
- Async Handler:
catchAsync
- API Features:
APIFeatures
- Handler Factory:
handlerFactory
- Authentication:
protect
,restrict
- File Upload:
updateTourPhotos
,resizeTourPhotos
,updateUserPhoto
,resizeuserPhoto
- TypeScript Configuration:
tsconfig.json
- ESLint Configuration:
eslint.config.mjs
- Prettier Configuration:
.prettierrc
- Nodemon Configuration:
nodemon.json
- Jest Configuration:
jest.config.js
- ✅ Create Docker Image 🐳
- ⏳ Add Caching with Redis ⚡️ for better performance and less calls to the database
- ✅ Add Clustering 🕸️ to improve scalability
- Added Dockerfile to containerize the application for consistent and portable deployment.
- Integrated PM2 for efficient process management, ensuring automatic restarts, logging, and clustering support.
- Implemented clustering to utilize all CPU cores, improving the application's scalability and performance under load.
DISCLAIMER: this API design is taken from jonas Schmedtmann NodeJs tutorial, I tried to re-implement it using typescript!
For more details, refer to the source code files linked above.